mp3 is recognized as application/x-gzip

If I upload a mp3 file,but that is recognized as application/x-gzip format (var_dump($mime_type); in mod/file/actions/upload.php)

I disabled all TP plugins, and have file and zaudio enabled.

Apache uses module and in /etc/mime.types mp3 is defined as audio/mpeg

Other mime types seem to be detected correctly. Also existing mp3 files are recognized correctly

I saw in  engine/classess/ElggFile.php that mime type is defined by php fileinfo . This module is installed  in /usr/lib64/php/modules/

It appears in both Elgg 1.8 and 1.9


So now I am stuck, suggestions are very welcome.

  • Add mapping filetypes into mod\file\views\default\object\file.php then extract mime type:

    $mime = $file->mimetype;


  • Thanks RvR, I tried that in start.php but now added it to the object

                    $mapping = array(
                            'audio/mpeg' => 'music',


    (I only copied the changed array element here)

    But does not help since the file is recognized as x-gzip.

  • What's the php version used on the server? If it's not php 5.3 or newer the mime type identification is more limited (and by my experience fails especially for mp3 files).

    Could it be that the mp3 that fails to be identified as mp3 has an id3 tag and the others that work have not? Or it might simply be a non-standard id3 tag that prevents correct identification. Though it's not fully correct to say "non-standard id3 tag" anyway as there is no definite standard which is one of the problems with mime type identification of mp3 files.

  • The php version is 5.5.17

    I never heard of any id3 tags, but I will look into it further. I did test different MP3 files and all failed. How to deal with this ID3 tags ?

  • @Gerard Look at my mod/file/actions/file/upload.php file version (added lines 120-125):

    • if ($info['extension'] =="mp3") {
    • $mime_type = "audio/mpeg";
    • }
    • if ($info['extension'] =="ogg") {
    • $mime_type = "audio/ogg";
    • }
  • It's been quite some time ago when someone also had problems with mp3 files not being identified correctly. Back then I did some tests on his site by uploading a mp3 file with and without an id3 tag (the id3 tag contains metainfo like song title, author, album etc.). I don't remember anymore how exactly I removed the id3 tags back then but you should be able to do so for example using the command line tool id3v2 on linux.

    Identification of mp3 files might not generally fail but depending on what version of the id3 tag is used. It seems that especially id3 version 1 is problematic because it does not have any fixed length. But then there are also ide version 2 in different subversions (2.3, 2.4 ...).

    Using id3v2 you can remove only specific tags or all tags:

    • id3v2 -D filename.mp3: removing of all tags,
    • id3v2 -s filename.mp3: removing only id3 version 1 tags,
    • id3v2 -d filename.mp3: removing only id3 version 2 tags,
    • id3v2 -C filename.mp3: converting an id3 version 1 into an id3 version 2 tag.

    Maybe you can find out more about when exactly the identification fails when experimenting a little bit with the id3 tag info included in the file. Unfortunately, I don't think there's any solution that will work in all cases even if you find out that it's indeed the id3 tag that is responsible for the identification to fail because the modification / removal of tag would have to happen on client side before uploading it.


    Identification of file type based on file extension is the fallback solution already in Elgg core. In Elgg core it's used only when fileinfo is unavailable and the browser does not report a file type (though the file type reported by the browser might also be wrong!).

    Maybe identification of file type based on file extension should also consider upper/lower case characters ("MP3"), maybe by converting all letters to lower case characters before comparing.

  • @RvR, thanks that works ! Great.

    @iionly, also thanks and tried that (stripping the id3 tags) but still did not recognize the correct mime type.


  • @iionly

    Identification of file type based on file extension is the fallback solution already in Elgg core

    Yepp, I know about it.

    But I'd similar issues with some filetypes (mp3, ogg, flv) as Gerard.

    The above tricks had able to help me only.