Reputation: 1392
It's annoying, I can't get the correct MIME type for many different files using php finfo().
Here's my little test program:
<? $finfo = new finfo(FILEINFO_MIME);
echo $finfo->file('/mnt/partage/Film/Sintel.2010.1080p.mkv');
Its output is completely incorrect:
application/octet-stream; charset=binary
Here's file -bi /mnt/partage/Film/Sintel.2010.1080p.mkv
output:
video/x-matroska; charset=binary
Apparently php finfo() doesn't use the proper magic file. However there aren't many options: either it's /usr/share/file/magic
or /etc/magic.mime
, none of them works from php.
I'm running this on Debian stable (wheezy) with backports libmagic. The problem occurs both when calling the program from Apache or the command line.
Upvotes: 3
Views: 1696
Reputation: 75568
Fileinfo uses data that is compiled with PHP. It does not use libmagic, so changing your libmagic has no effect on PHP. The only option is to use a newer PHP version, or compile it yourself with a new data file.
Edit: or pass the $magic_file
parameter to finfo_open, or set the MAGIC
environment variable.
Upvotes: 3
Reputation: 2815
MIME types are not similar on different OS. I am afraid you can't just rely on MIME types. I would suggest to do check on extension or add all possible MIME types for a file type. I had the same issue few weeks ago and I had to rely on extension of the file.
You can try with :
$info = pathinfo($file);
echo $info['extension']; //Will be mkv in your case
Upvotes: 0