mime_content_type() for PNG image returns "text/plain"

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
PHP 4.3.8 with UNIX  with option --with-magic_mime

[PHP] echo mime_content_type('/images/myimage.png'); // RETURNS

PHP 4.3.11 with UNIX with option --with-magic_mime

[PHP] echo mime_content_type('/images/myimgae.png'); // RETURNS

PHP 4.3.2 and 4.3.6 with UNIX, PHP 5.0.4 with Windows (w/o magic_mime

[PHP] echo mime_content_type('/images/myimage.png'); // RETURNS

I am having to shut off support within a portable web application that
will be housed, at least, in the following environments:

1. PHP 4.3.2/UNIX
2. PHP 4.1.2/UNIX
3. PHP 4.3.6/UNIX
4. PHP 4.3.11/UNIX
5. PHP 5.0.4/Windows

this means that the environment must be universal for this to work, and
in the case of a few test environments that were running 4.3.11 -
5.0.4, mime_content_type() under PHP supporting --with-magic_mime would
always return [Quote]text/plain[/Quote] and not

I think this is a bug but cannot independently verify this unless
someone else here duplicates my test, provided they too are running PHP
4.3.8+ with --with-magic_mime support enabled and see if they get the
same results.  Otherwise, how do I work around this problem? [Note: I
wrote my own "mime_content_type()" function that works just fine)


Re: mime_content_type() for PNG image returns "text/plain"

comp.lang.php wrote:

Quoted text here. Click to load it


did you try:  
// $f is path to file
$f = escapeshellarg($f);
$mimetype = trim( `file -bi $f` );

Maybe that works on all systems. (Not tested)

Erwin Moller

Re: mime_content_type() for PNG image returns "text/plain"

I have that in my local "mime_content_type()" function I wrote.  But
because this version of PHP (4.3.11) comes with --with-magic_mime
enabled, I am unable to use my version of "mime_content_type()" and am
forced to use theirs.


Re: mime_content_type() for PNG image returns "text/plain"

Oh one more thing, that does not work on Windows (don't know about Mac
or Solaris), so I'm afraid it doesn't work on all systems.  On Windows
you're basically screwed and have to look at the ext and pray it's


Site Timeline