Edit report at https://bugs.php.net/bug.php?id=53035&edit=1

 ID:                 53035
 Comment by:         shawn at thesignchef dot com
 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
 Private report:     N

 New Comment:

I am having the same issue still. Has this been fixed or is there a workaround. 
Thanks so much.


Previous Comments:
------------------------------------------------------------------------
[2010-11-09 16:57:47] stephane at emark dot nl

Hi, I just want to say that I experience the same problem.

As fel...@php.net mentionned, if you have any type of comments at the top of 
your 
file, the problem occurs. 
For example, if i try to get the mime type of a js file with comments at the 
top, 
it returns "text/x-c", if i remove the comments, then it returns "text/plain", 
which in and of itself is not correct as it should return 'text/javascript'.

Any idea how to circumvent this problem other than removing all my comments ?!?!

------------------------------------------------------------------------
[2010-10-13 00:38:01] stuart at horuskol dot net

"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?

------------------------------------------------------------------------
[2010-10-12 07:52:11] ahar...@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] fel...@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 https://bugs.php.net/bug.php?id=53035&edit=1

Reply via email to