|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-04-20 14:28 UTC] 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. Patchesput_a_AT_in_start_of_line (last revision 2013-04-20 14:36 UTC by rg at mejoramos dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 01:00:01 2025 UTC |
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.