Search code examples
phphtmlfirefoxuploadmp3

mp3 upload mimetype being missed by firefox specically


I have a file upload, it works great in everything except for firefox, it keeps saying the mimetype isnt supported. This is my code:

 if(isset($_POST[submitfile]))
 {
     $uploadedsong = $_FILES['soup']['tmp_name'];
           $mimetype = $_FILES['soup']['type'];
                 if($mimetype=="audio/mpeg"||$mimetype=="audio/x-mpeg-3"||$mimetype=="audio/mp3"||$mimetype=="audio/x-mpeg"||$mimetype=="audio/x-mp3"||$mimetype=="audio/mpeg3"||$mimetype=="audio/x-mpeg3"||$mimetype=="audio/mpg"||$mimetype=="audio/x-mpg"||$mimetype=="audio/x-mpegaudio")
                 {

This is allowing uploads for every browser, EXCEPT firefox! extremely frustrating, i dont know why this is happening. Any ideas?


Solution

  • The mime-type for the file-upload is totally informative and not further explicitly (and specifically) binding of what's-o-ever. Don't rely to it.

    Firefox is doing nothing wrong here, it's the wrong expectations you've coded into your script - from the PHP Manual­Docs:

    $_FILES['userfile']['type']

    The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted.

    So the use of this information is limited, it is not strict.

    You should log which mime-type was uploaded, because you can't test against all browser/OS combinations.

    Inspecting the file is necessary as well if you want to ensure it follows the convention of a mp3 file. Next to fileinfo­Docs (which is for all files), there is php-reader and Zend_Mimme_Magic and a lot of other mp3 files related libraries.