开发者

finfo path not found

I'm on 5.3.1 and after reading the docs, I see that fileinfo is included and that pecl is no longer required. I an however getting:

finfo_file(): File or path not found

I'm not sure what it's looking for. I've enabled the extension in the ini file and attempted to run the exam开发者_JAVA技巧ple from the PHP site:

$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
foreach (glob("*") as $filename) {
    echo finfo_file($finfo, $filename) . "\n";
}
finfo_close($finfo);

Can someone tell me what file I need?


I've just discovered from my hosting company that the path to the elusive magic.mime file is to be found when running phpinfo(): look for the entry "mime_magic.magicfile". If it's not listed, contact your hosting company and explain you need this file and path for PHP finfo(). Worked for me.


You need to either configure your environment so PHP knows where the "magic database file" is, or, as another possibility, when calling fileinfo_open, you need to specify the path to the magic database file (quoting) :

Name of a magic database file, usually something like /path/to/magic.mime.
If not specified, the MAGIC environment variable is used.
If this variable is not set either, /usr/share/misc/magic is used by default. A .mime and/or .mgc suffix is added if needed.


See the example given on the manual page of fileinfo_open, for instance (quoting) :

$finfo = finfo_open(FILEINFO_MIME, "/usr/share/misc/magic"); // return mime type ala mimetype extension

if (!$finfo) {
    echo "Opening fileinfo database failed";
    exit();
}

/* get mime-type for a specific file */
$filename = "/usr/local/something.txt";
echo finfo_file($finfo, $filename);

/* close connection */
finfo_close($finfo);

Of course, up to you to find where that file is on your system...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜