Jim
Jim

Reputation: 5

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 example 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?

Upvotes: 0

Views: 5411

Answers (2)

Rob Banmeadows
Rob Banmeadows

Reputation: 105

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.

Upvotes: 2

Pascal MARTIN
Pascal MARTIN

Reputation: 401142

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...

Upvotes: 0

Related Questions