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

 ID:                 64684
 Comment by:         rg at mejoramos dot com
 Reported by:        rg at mejoramos dot com
 Summary:            FILEINFO_MIME_ENCODING fail
 Status:             Not a bug
 Type:               Bug
 Package:            *Directory/Filesystem functions
 Operating System:   Windoqs and Linux
 PHP Version:        5.3.24
 Assigned To:        ab
 Block user comment: N
 Private report:     N

 New Comment:

Thanks by you help.

>>>the file is way too short, and that's the issue.
>>>libmagic needs at least a few bytes at the start of a file to do the magic.

Mmm...

If you remove the number (if file is EMPTY), then PHP don´t cry.

Conclution:
The issue is more than of Magic, and no of PHP ¿?


Previous Comments:
------------------------------------------------------------------------
[2013-04-22 07:31:01] a...@php.net

Thanks for reporting this. Now I get the behavior you've described. You 
literally put only one char 0x30 into the file, and that's exactly the issue. 
Previously I've tested with a kind of file created manually, but an editor 
automatically appends some chars there. So to get such a case on has to create 
it with a hex editor or just php -r 'file_put_contents("file", "0")'; 

I'd consider this one as not a bug. If I run "file action_number" with your 
file on the Linux shell, here's the output:

action_number: very short file (no magic)

Running "file --mime --mime-encoding action_number"  says

action_number: application/octet-stream

which is a normal fallback.

Thus - the file is way too short, and that's the issue. libmagic needs at least 
a few bytes at the start of a file to do the magic.

For your case - if you know there's only a number in that file, no need to 
check the charset. It'll be always ascii. Either it's a number which you read 
in and cast integer, or it's invalid - I'd do so.

------------------------------------------------------------------------
[2013-04-21 17:38:46] rg at mejoramos dot com

Thanks by you interest.

You can see ALL DETAIL by download:

http://utp.guirv.com/descargas/?f=/PHP_BUG_64684.rar
(318 bits)

When you run in Windows:
Warning: finfo_file(): Failed identify data 0:(null) in E:\HTTP... 
...\PHP_BUG_64684\fileinfo.php on line 3 

When you run in Linux CentOs:
 Warning: finfo_file() [function.finfo-file]: Failed identify data 0:(null) in 
/home/... .../PHP_BUG_64684/fileinfo.php on line 3

------------------------------------------------------------------------
[2013-04-21 16:28:56] a...@php.net

I can't reproduce this using your snippet, I get us-ascii and that will be it 
in any case. For that I've created a file containing just 0. 

And, you might anyway be interested on the next 5.4 release as libmagic was 
upgraded, or already test the latest windows snapshot from 
http://windows.php.net/downloads/snaps/php-5.4/ .

To reproduce this issue a reliable snippet in required.

------------------------------------------------------------------------
[2013-04-20 14:28:05] rg at mejoramos dot com

Description:
------------
If FILE have contain exactly the string:
"0"
without quotes, then:

in Windows output:
Warning: finfo_file(): Failed identify data 0:(null) in ...

in Linux output:
Warning: finfo_file() [function.finfo-file]: Failed identify data 0:(null) in 
...

Why file have a "0" ?
becouse I need read a integer in range 0-25 to take some decisions...

Why I run finfo_file() ?
Becouse I need know if last edition create UTF8 or ISO-8859-1



Test script:
---------------
echo 'Encoding: 
'.finfo_file($finfo,$_FILES['name_in_FORM']['tmp_name'],FILEINFO_MIME_ENCODING);

Remember: target file contain only the string: "0" without quotes.



------------------------------------------------------------------------



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

Reply via email to