Stephen Gran on 26 Jul 2006 16:49:04 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] PHP Mime detection


On Wed, Jul 26, 2006 at 12:20:33PM -0400, Aaron Crosman said:
> I'm working on a Debian 3.1 server, running Apache 2 and PHP 4.3.  The
> mime_content_type function in PHP does not properly detect MP3 files.
> Images see to come through fine, but it always defaults to text/plain
> for MP3s.  Mod_mime_magic is running in Apache, and PHP is not giving
> any errors that I can find.
> 
> I checked the /usr/share/misc/file/magic.mime and the MP3 definitions
> look like everything I can find online:
> 
> # MPEG Layer 3 sound files
> 0       beshort&0xfffe  =0xfffa         audio/mpeg
> #MP3 with ID3 tag
> 0       string          ID3             audio/mpeg
> 
> I noticed the problem when working with drupal, but I wrote a simple php
> test page to see if mime_magic was working at all.  The relevant code
> follows:
> 
> Image:  <?=mime_content_type('/path/to/image.jpg')?> <br />
> MP3 File: <?=mime_content_type('/path/to/AudioFile.mp3')?> 
> 
> Results in:
> 
> Image: image/jpeg
> MP3 File: text/plain
> 
> Anyone have thoughts of suggestions?

First, run file on the file in question.  If file also thinks it's
text/plain, then either the mp3 is busted, or you are overriding mime
types somewhere.

To see if you're overriding mime types somewhere, strace it, and look for
what it opens, to see if the default mime handling is getting overridden
anywhere.

strace -ff -e open php tmp.php
(where tmp.php is your script above)

You will get a bunch of of lines like:
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib/tls/i686/cmov/libnss_files.so.2", O_RDONLY) = 3
open("/etc/protocols", O_RDONLY)        = 3
open("/etc/protocols", O_RDONLY)        = 3
open("/usr/share/file/magic.mime", O_RDONLY) = 3

That last one is the important one here - if you have others, you'll
want to see if they accidentally or purposely override what's set in
that file.

If you're not overriding mime types, then the file is likely busted.
Does it actually have the magic bits at the beginning?  The first one I
looked at has 'ID3' as the first 3 characters of the file, which agrees
with the above file magic.

Take care,
-- 
 --------------------------------------------------------------------------
|  Stephen Gran                  | When the speaker and he to whom he is   |
|  steve@lobefin.net             | speaks do not understand, that is       |
|  http://www.lobefin.net/~steve | metaphysics.   -- Voltaire              |
 --------------------------------------------------------------------------

Attachment: signature.asc
Description: Digital signature

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug