|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-07-11 12:46 UTC] majkl578 at gmail dot com
Description:
------------
When finfo is used with FILEINFO_MIME flag for a file, it returns mime type + charset (in this format: mime/type; charset=foo
Configure Command:
'./configure' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-mysql' '--with-mysqli' '--with-curl' '--with-sqlite' '--with-gd' '--enable-mbstring' '--with-openssl' '--disable-short-tags' '--with-mcrypt' '--with-bz2' '--with-zlib' '--enable-zip'
Reproduce code:
---------------
$obj = new \finfo(FILEINFO_MIME);
echo $obj->file('/tmp/phpbug'); //in file is plain text
Expected result:
----------------
text/plain
Actual result:
--------------
text/plain; charset=us-ascii
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 16 06:00:02 2025 UTC |
I beg to differ a bit here with the assertion that the change is not a BC break. Consider this: in versions prior to 5.3.0, one could do a match like this: $finfo = new finfo(FILEINFO_MIME); $type = $finfo->file($filename); if (!in_array($type, array('image/jpeg', 'image/jpg'))) { echo "Invalid image type."; } else { echo "JPEG found." } Now, with 5.3.0, this changes; the same assertion no longer works. This is in fact exactly an issue we had with Zend_Validate_File_MimeType when testing against PHP 5.3.0 -- matching that worked in 5.2.x now no longer works in 5.3.0. We have altered our library to handle the strings returned by both versions, but that exactly disproves your point: if the new behavior were BC, we wouldn't *need* to update our code. I feel at the very least, the fact that the MIME type returned also includes encoding information, and the format of this encoding information, needs to be documented in the manual, and likely the UPGRADING guide.I used to do a direct comparison, for example if($mimeInfo = 'image/jpeg') ... But then, with this changes, the comparison broke. Fortunately I have a custom findStr() function that does the job. if(findStr('image/jpeg',$mimeInfo)) ... this solved my problem easily.scottmac: Thank you, the constant you've added works like a charm. philip: On my Debian server, libmagic1 library is in version 4.26-1. mohdyusuf: try this: ------ $obj = new finfo(FILEINFO_MIME_TYPE); echo $obj->file('/tmp/whatever'); ------ Thank you.