php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56999 Fileinfo Failed to load magic database
Submitted: 2006-05-04 05:13 UTC Modified: 2006-10-11 20:10 UTC
From: humbads at alum dot mit dot edu Assigned:
Status: Not a bug Package: Fileinfo (PECL)
PHP Version: 5.1.2 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2006-05-04 05:13 UTC] humbads at alum dot mit dot edu
Description:
------------
The fileinfo extension won't recognize the magic database path, regardless of whether it is specified in the INI file or in the finfo constructor.  Even if I put magic.mime in the root folder "C:\" or in the working folder ".", it doesn't work.

PHP.INI:
; path to mime types file
mime_magic.magicfile = "C:\Program Files\PHP\extras\magic.mime"
extension=php_fileinfo.dll
extension=php_mime_magic.dll

IUSR_MachineName has read & execute permission to the magic.mime file.  Using latest release PHP 5.1.2 and PECL DLLs.

Reproduce code:
---------------
// ERROR ONE:
$finfo = new finfo(FILEINFO_MIME);
print $finfo->buffer("abc");

// Warning: finfo::finfo() [function.finfo]: Failed to load magic database at '(null)'.

// ERROR TWO:
$finfo = new finfo(FILEINFO_MIME, 'C:\Program Files\PHP\extras\magic.mime');
print $finfo->buffer("abc");

// Failed to load magic database at 'C:\Program Files\PHP\extras\magic.mime'

Expected result:
----------------
It should print the mime type.

Actual result:
--------------
Gives the warning described above, then gives a warning like "invalid fileinfo object" for the finfo->buffer statement.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-25 22:01 UTC] torsten at alpha-hasi dot de
Same problem here! Help needed!

***** *****

win2000 (german)
Apache/2.2.2 (Win32) 
PHP/5.1.4

***** *****

php.ini includes "extension=php_fileinfo.dll",
paths are set accurate, the file magic.mime is in the right directory

***** php-code: *****

$finfo = finfo_open(FILEINFO_MIME);
foreach (glob("*") as $filename) {
   echo finfo_file($finfo, $filename) . "\n";
}
finfo_close($finfo);

***** error: *****

Warning: finfo_open(): Failed to load magic database at '(null)'. in test.php on line 11

***** by the way *****

By using "mime_content_type()" there is an error, too:

Warning: mime_content_type(): mime_magic not initialized

***** *****

I need a way to identify my files urgently ...
 [2006-07-21 12:33 UTC] south dot minds at gmail dot com
I had the same problem using php 5.1.4 on win2k. Just found that it works if you give the full path to the magic.mime file *without* the extension.i.e.:
 "C:\Program Files\PHP\extras\magic"
fileinfo will add it for you.
I guess php manual is rather unclear about this.
 [2006-10-11 20:10 UTC] ilia at prohost dot org
The extension is something that's added automatically by the 
library, you don't need to specify it.
 [2007-02-06 00:18 UTC] xenleire at gmail dot com
take note that finfi_open() or the finfo constructor takes a second optional argument (a string) where you can specify the path of your magic.mime. if you don't specify one, php will use the value in the MAGIC environment variable, not the mime_magic.magicfile

i use a windows system as well, and as noted by south dot minds at gmail dot com, you need to remove the ".mime" extension type to make it work
 [2007-02-06 00:19 UTC] xenleire at gmail dot com
oops, i meant to say finfo_open()
 [2007-03-03 22:29 UTC] nomadcanuck at yahoo dot com
Here is how I resolved this issue without extra coding.

Warning: finfo_open() [function.finfo-open]: Failed to load magic database at '(null)'.

$finfo = finfo_open(FILEINFO_MIME, 'C:/wamp/php/extras/magic');

Where file "magic.mime" exists in "C:/wamp/php/extras/magic"
 [2007-03-03 22:33 UTC] nomadcanuck at yahoo dot com
I'm sorry I did not explain that "C:/wamp/php/extras/magic" is actually directory path "C:/wamp/php/extras/" with magic appended to the directory path. Removing .mime from the filename did not work for me.
 [2007-06-26 16:10 UTC] xprezez at go2 dot pl
Removing the extension from "magic.mime" file worked for me (i.e. change to just "magic").
 [2007-06-26 16:59 UTC] xprezez at go2 dot pl
Sorry, I was to quick to say it worked.
The mime.magic provided with php is not enough.
Actually what I needed to get it working on windows was four magic database files (magic.mime, magic.mime.mgc, magic, magic.mgc).
In call to the finfo_open just specify "c:/path/.../magic", skipping the extensions.
 [2007-08-03 16:30 UTC] christophe dot charron dot xul at gmail dot com
I confirm that with wamp5 (Apache/2.2.4 (Win32) PHP/5.2.3)
I had to download http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=1
8878 and put the four magic
database files (magic.mime, magic.mime.mgc, magic, magic.mgc) in the good directory. I had to use realpath($myfilename) instead of $myfilename and then it seems to be ok.
Here is a script

<?php
$name="./sample/message.eml";
if( file_exists($name) ) {
  $finfo = finfo_open(FILEINFO_MIME,"C:/wamp/php/extras/magic");
  var_dump($finfo);
  $mime=finfo_file($finfo, realpath($name));
  finfo_close($finfo);
  echo $mime;
} else {
echo "nop";
}
?>
 [2007-09-14 01:44 UTC] shahul dot it at gmail dot com
i need to install libmagic i am getting error 
call to undefined function finfo_open() i need some help
 [2008-02-09 13:17 UTC] tuan_ngo2001 at yahoo dot com
Thank you all. Following your instructions, here is what i did get it work:

1. Go to http://pecl4win.php.net/list.php to get php_fileinfo.dll and have this dll declared in php.ini (extension=php_mime_magic.dll)

2. Go to http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=18878, extract the downloaded file. Look for files "magic" and "magic.mime" and have them under php extras directory. (Note: php.2.5 magic.mime gave wrong mime type).

3. My script looks like:

$handle = finfo_open(FILEINFO_MIME,'c:\php52\extras\magic');
$mime_type = finfo_file($handle,$file);

Regards
 [2008-05-08 06:15 UTC] tomfreeman33 at gmail dot com
I have just followed these instructions and successfully setup on WAMP5 running PHP 5.2.4. I did the following:

1. Enable php extensions for php_fileinfo and php_mime_magic.
2. Download the 4 magic files from http://sourceforge.net/project/showfiles.php?group_id=23617&package_id=18878 and place in the extras directory. In my case c:\wamp\php\extras

Some of that might not be necessary but it worked for me.
 [2008-07-16 09:50 UTC] genoil at hotmail dot com
make sure touse single quotes on the path to magic, or else it will still fail.
 [2008-07-21 11:29 UTC] safetyfast at hughes dot net
I installed the GNUwin32 package, but it only provided magic and magic.mgc - I am still missing magic.mime and magic.mime.mgc.  Any thoughts on where to get them?  Thanks.
 [2008-07-24 09:11 UTC] aekko85 at hotmail dot fr
I also can't find 2 of the 4 magic files. Any clues to why this is ?
Thanks.
 [2008-08-15 15:09 UTC] will at vousden dot me dot uk
You need to download an older version of the library. The latest version that includes all 4 files is 4.23:
http://downloads.sourceforge.net/gnuwin32/file-4.23-bin.zip?modtime=1213447945&big_mirror=1

You may also need to set the MAGIC environment variable, as detailed here:
http://usphp.com/manual/en/fileinfo.installation.php

Using these two links fixed it for me :)
 [2009-07-19 22:53 UTC] chinadans at yahoo dot com dot cn
dfsdf
 [2012-10-11 09:37 UTC] muratgol26 at gmail dot com
awssddsdasdad
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 13:01:52 2019 UTC