Jump to content

Recommended Posts

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 ..?

Link to comment
https://forums.phpfreaks.com/topic/140044-checking-mime-file-type/
Share on other sites

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"];

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.