|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2008-09-05 07:33 UTC] gregor at gregor dot ru
 Description:
------------
Fileinfo module isn't works. It generates exception.
I've checked $finfo object exactly before $finfo->file() call and get_classname() correctly returns "finfo" and 0 get_class_methods() returns "[0] => finfo [1] => set_flags [2] => file [3] => buffer".
BTW: There is not method "close"!
I'm using php 5.2.6 (!) and pecl package which comes with it.
Reproduce code:
---------------
$filename='/webserver/sites/test/uploads/test.jpg';
$finfo = new finfo(FILEINFO_MIME, '/webserver/php/magic');
if (!$finfo) die("Can't open mime database");
$res = $finfo->file($filename);
print($res);
Expected result:
----------------
image/jpeg
Actual result:
--------------
Warning: finfo::file() [finfo.file]: The invalid fileinfo object.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 06:00:01 2025 UTC | 
I can reproduce this also on Centos 5.2 with PHP 5.2.11 and Apache/2.2.3 (fileinfo installed within PECL). If I set the environment (like manual says): putenv('MAGIC=/usr/share/file/magic'); => it's not taken into consideration If I set as 2nd parameter the mime file like: // file on disk: /etc/httpd/magic.mime $finfo = new finfo(FILEINFO_MIME, '/etc/httpd/magic'); => it validates the creation of the object but than I get a lot of errors like: "Warning: finfo::file() [finfo.file]: The invalid fileinfo object. in /www/projects/andrei/fileinfo/fileinfo.php on line 38 1.xlsx" So my only solution was to leave default PHP configuration and copy my magic file into: /usr/share/misc/magic.mime P.S. We cannot move to PHP 5.3 since we have an old(<2002) and large application and code was not refactored (yet! - hopefully).