tags:

views:

22

answers:

1

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?

A: 

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

Pascal MARTIN
Hey Pascal, thanks for the hand here. I was under the impression that the mime database was included and that I didn't need to download it. I have no idea where it is. I just checked the PHP directory and there is no magic mime or mime file. Are you certain that I need it if I'm on 5.3.1?
Jim
That mime database is not specifically related to PHP -- it's probably provided by some other package...
Pascal MARTIN
Ok, do I need it or is it bundled in 5.3? I'm under the impression that it is bundled. I'm also looking for it on the net and can't find it. The last place I it was located on the PECL site but I can't find that either.
Jim
No, that database is not provided by PHP (so, not bundled) : PHP is only using it. Which means it must be installed from "somewhere" ;; there are a couple of informations in the user notes of http://php.net/manual/en/function.finfo-open.php ; maybe those might help.
Pascal MARTIN
Thanks for the links Pascal. Would you happen to know where I can pick up a copy of this mysterious file? I can't fins it anywhere and just came from the link you provided and there is no reference there either.
Jim
Pascal, I think I just found it. Another guy posted his horrid experience with not being able to locate that file either so he posted the link. One thing I don't understand is how PHP can develop functions that require an external file and not even provide the link. Sheesh. :)
Jim