Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts

    mime type problem

    Hi well this works fine for Firefox but not for IE.

    $typefile = $_FILES['fuploadaud']['type'][0];

    FF the array looks like this

    FF
    Array ( [name] => Array ( [0] => character.mp3 ) [type] => Array ( [0] => audio/mpeg ) [tmp_name] => Array ( [0] => /tmp/phpfWh1qo ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 643635 ) )

    and IE like this

    IE
    Array ( [name] => Array ( [0] => character.mp3 ) [type] => Array ( [0] => application/octet-stream ) [tmp_name] => Array ( [0] => /tmp/php64T6QL ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 643635 ) )

    Hense this is the issue application/octet-stream with my mp3 uploader.

    Now i do check the extension also so i guess i could just skip the type check if the browser is ie but there has to be a better way.

    I also read this thread

    Retrieving content-type of a file



    Which when i follow the directions tells me that undefined function finfo_open()

    so i tried the deprecated deal and it tells me

    undefined function mime_content_type()

    so now i dont know what to do.

    Any ideas.. thanks

    Since i am checking the extension should i just skip this if it is ie.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Neither the type nor the extension are actually sufficient depending on how secure you want to get.
    The browser provides the type, so that's why you are seeing two different types. FF understands what an mp3 is and IE seems to ignore that its an audio file and claiming its a generic stream.
    fileinfo requires either PHP 5.3.0+ OR pecl 0.1.0+ to function. mime_content_type looks like it should be available pretty much in any version of PHP since 4.3, and the api doesn't directly indicate which version it was removed in (changelogs would, but I'm too lazy to check there). So you should enable your finfo instead, or if you're version is < 5.3.0, install the pecl required for the finfo.
    You can of course work it out manually. If you're looking for specific filetypes to upload, you can simply open them up and parse the headers for information, and compare them to known structure to see if they match. If so, chances are the file is good. Images are the easiest since you could simply pass a file read to the imagecreatefromstring function and if it generates a resource its good to go. Pretty much any other mime would require more work though.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    durangod (07-06-2013)

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts
    Thanks Fou-Lu nice explanation and i appreciate the reply.

  • #4
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,341
    Thanks
    260
    Thanked 32 Times in 31 Posts
    Just wanted to share this as well. ID3 is the metadata container that is associated with MP3 so that is what we need to find in the header.

    Here is what i have that produces that output.

    Code:
                  // open the file and check header 
    
                 if (!($handle = fopen($tempOne, 'rb')))       //opens the temp file that is being uploaded
                  {
                   $err_message = "Error Opening $nameOne";      //displays normal file name to user if error               
                    fclose($handle);
                     }else{
                           $hdr = fread($handle, 3); //should grab ID3  if it is a mp3
                            fclose($handle);
                           }//close else
    
                  //for testing only
                   print_r($hdr);
                   exit;
    
    //The output is confirmed as ID3 in my case


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •