sh0wtym3 Posted January 8, 2009 Share Posted January 8, 2009 Hey all, I want to restrict uploads to mp3 and wav only using the script below: //Begin function upload(){ if(count($_FILES["item_file"]['name'])>0) { //check if any file uploaded $GLOBALS['msg'] = ""; //initiate the global message for($j=0; $j < count($_FILES["item_file"]['name']); $j++) { //loop the uploaded file array $filen = $_FILES["item_file"]['name']["$j"]; //file name //Set allowed MIME types and get the filetype $allowed_mime_types = array('audio/mpeg','audio/x-wav'); $filetype = filetype($_FILES["item_file"]['type']["$j"]); //Renames the music file $file = str_replace(' ', '_', $filen); $file = strtolower($file); //Remove everything except a-z, 0-9, and underscores $file = preg_replace('/[^\w\.]/i', '', $file); //Check type and BEGIN UPLOAD PROCESS if(in_array($filetype,$allowed_mime_types)) { And I get the following error: Warning: filetype() [function.filetype]: Lstat failed for audio/wav in /home1/mysite/public_html/test.php on line 109 Line 109 is $filetype = filetype($_FILES["item_file"]['type']["$j"]); It seems like its reading the filetype right (audio/wav) but I don't understand why it's kicking out this error ..? Quote Link to comment https://forums.phpfreaks.com/topic/140044-checking-mime-file-type/ Share on other sites More sharing options...
premiso Posted January 8, 2009 Share Posted January 8, 2009 I think that filetype needs to be called on the actual file name, you already have the type apparently just be calling the $_FILES array index of ['type'] like you have shown..... Quote Link to comment https://forums.phpfreaks.com/topic/140044-checking-mime-file-type/#findComment-732714 Share on other sites More sharing options...
Brian W Posted January 8, 2009 Share Posted January 8, 2009 filetype() gets the file type. The parameter going into it is "audio/wav" where it should be something like "path/sound.wav". It also returns whether the path is a file or directory (or some other things). It does not return the mime type. see http://us3.php.net/filetype $filetype = filetype($_FILES["item_file"]['type']["$j"]); to- $filetype = $_FILES["item_file"]['type']["$j"]; Quote Link to comment https://forums.phpfreaks.com/topic/140044-checking-mime-file-type/#findComment-732715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.