etsted Posted August 24, 2014 Share Posted August 24, 2014 // this makes every file name unique $fileName = $_FILES['Filedata']['name']; $kaboom = explode(".",$fileName); $ext = ""; $ext = end($kaboom); $ext = strtolower($ext); $fileName = date("YmdjzHhisu") . rand(10000000,99999999) . ".$ext"; // defines what the ext can be $imageTypes = array('jpg','jpeg','gif','png'); $videoTypes = array('mp4','webm','ogg','wmv'); $audioTypes = array('mp3','ogg','wav'); $title = $_POST['title']; $description = $_POST['description']; $username = $_POST['username']; // include DB connection include_once ("../connect.php"); // use the pathinfo to match the ext of the uploaded file $fileParts = pathinfo($_FILES['Filedata']['name']); $fileParts = $fileParts['extension']; $fileParts = strtolower($fileParts); if (in_array($fileParts,$imageTypes)) { // this is for images // insert into DB $sql = "INSERT INTO images VALUES('', '$title', '$description', '$username', '$fileName' , NOW(), '')"; $query = mysqli_query($con, $sql); move_uploaded_file($tempFile, "../u_image/" . $fileName); echo '1'; } else if(in_array($fileParts, $videoTypes)){ // this is for videos // insert into DB $sql = "INSERT INTO videos VALUES('', '$title', '$description', '$username', '$fileName' , NOW(), '')"; $query = mysqli_query($con, $sql); move_uploaded_file($tempFile, "../videos/" . $fileName); echo '1'; } else if(in_array($fileParts,$audioTypes)){ // this is for audios // insert into DB $sql = "INSERT INTO mp3 VALUES('', '$title', '$description', '$username', '$fileName' , NOW(), '')"; $query = mysqli_query($con, $sql); move_uploaded_file($tempFile, "../audio/" . $fileName); echo '1'; } else { echo "Invalid file."; } this script is supposed to store images , videos and mp3. It only store images not mp3 or video file. I have created the map for mp3 videos and images. Link to comment Share on other sites More sharing options...
JamesB Posted August 24, 2014 Share Posted August 24, 2014 Check the following settings in your php.ini file or with ini_get() http://php.net/manual/en/function.ini-get.php upload_max_filesize post_max_size As the file size could be exceeding these. 1 Link to comment Share on other sites More sharing options...
Don Jajo Posted August 27, 2014 Share Posted August 27, 2014 ...also, use pathinfo () function to get file extension, i might have a period in my file name before the extension and that gets you an error http://www.w3schools.com/php/func_filesystem_pathinfo.asp Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now