Edit report at http://bugs.php.net/bug.php?id=53035&edit=1
ID: 53035
Comment by: stuart at horuskol dot net
Reported by: stuart at horuskol dot net
Summary: finfo_file() returns incorrect mimetype
Status: Bogus
Type: Bug
Package: Filesystem function related
Operating System: Linux/Ubuntu 10.04
PHP Version: Irrelevant
Block user comment: N
New Comment:
"however, the command line tool 'mimetype' correctly identifies the file
using the same library at '/usr/share/misc/magic'"
I tested using the -M switch (as in my example/test script):
mimetype -DM --database /usr/share/misc/magic /path/to/file/reset.css
and this tells me the file is text/css on my platform - are you sure
you're using the same magic database?
Previous Comments:
------------------------------------------------------------------------
[2010-10-12 07:52:11] aharvey@php.net
I get the same result from the command line "file" program on Ubuntu
10.10:
$ curl -s http://horuskol.net/reset.css | file
--mime-type -
/dev/stdin: text/x-c
mimetype also believes it's C source:
$ mimetype -DM reset.css
> Data dirs are: /home/aharvey/.local/share, /usr/share/gnome,
/usr/local/share, /usr/share
> Checking all magic rules> Value "/*" at offset 2 matches at /usr/share/mime/magic line 1136
reset.css: text/x-csrc
The only way I can get mimetype to return text/css is if it also looks
at the extension (ie is called without -M).
I can't really see any way this is a PHP bug, given other programs using
the same magic database are resulting in the same file being detected as
C source. Closing.
------------------------------------------------------------------------
[2010-10-11 15:39:35] felipe@php.net
Strange... It's caused by the comment in the begin of the CSS file.
------------------------------------------------------------------------
[2010-10-10 13:37:04] stuart at horuskol dot net
Description:
------------
This is tested on:
PHP 5.3.2-1ubuntu4.5 with Suhosin-Patch (cli) (built: Sep 17 2010
13:49:46)
file_info() is reporting a CSS file has having the mimetype 'text/x-c'
instead of 'text/css'
however, the command line tool 'mimetype' correctly identifies the file
using the same library at '/usr/share/misc/magic'
the file being tested is available at http://horuskol.net/reset.css
Test script:
---------------
PHP:
$finfo = new finfo(FILEINFO_MIME);
var_dump($finfo->file('/path/to/file/reset.css'));
$finfo = new finfo(FILEINFO_MIME, '/usr/share/misc/magic');
var_dump($finfo->file('/path/to/file/reset.css'));
$finfo = finfo_open(FILEINFO_MIME, '/usr/share/misc/magic');
var_dump(finfo_file($finfo, '/path/to/file/reset.css'));
Command Line:
mimetype -DM --database /usr/share/misc/magic /path/to/file/reset.css
Expected result:
----------------
string(26) "text/css; charset=us-ascii"
Actual result:
--------------
string(26) "text/x-c; charset=us-ascii"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53035&edit=1