Fileinfo could not load the magic file
seaneffel - September 9, 2008 - 20:56
| Project: | MimeDetect |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
I'm installing this module on two instances of Drupal on the same server, one is 5.x and one is 6.x. I get the following message on both:
"Fileinfo could not load the magic file. It could be corrupted. Try reinstalling the magic file distributed with the MimeDetect module. (Currently using Mime type detection PHP Fileinfo Extension)"
I've tried with various file permissions, but beyond that I don't know. It's likely to be a server config issue.
From status report:
Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7a mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.2.6
Thanks for the help.

#1
I am having this problem too, any help would be appreciated. This is on Drupal 5.10; I have the same web server results from the status report.
#2
I have the same experience on D6 using Windows/IIS
#3
Reporting same problem here. Been troubleshooting off and on for days.
#4
Changed name to better reflect the issue we're having. That magic file isn't so magical, now is it.
#5
I guess the magic file supplied by the module have some sort of conflict with the fileinfo extension installed on the server. In my server that complain about this, I found the system installed magic files in /usr/share. So I made the follow change - change the line below in the function mimedetect_requirements
if (!$finfo = @finfo_open(FILEINFO_MIME, drupal_get_path('module', 'mimedetect') .'/magic')) {
to
if (!$finfo = @finfo_open(FILEINFO_MIME, '/usr/share/magic')) {
after that, I saw no more of this error.
If you do so, then you should also change the similar line in function mimedetect_mime, I think.
Maybe the author of this module could add another config variable, and have the website admin fill in where they have their magic files, if they have fileinfo enabled at all.
#6
Tried everything for days, nnn's suggestion in comment #5 finally got rid of the error without affecting (as far as I can tell) the behavior of the module.
#7
I wrote an oneliner patch to fix this issue.
#8
here's the patch for D6.
#9
actually this needs to update mimedetect_mime() since that's also trying to load the "magic" file... i need to get the fileinfo extension built so i can test if we should be passing it "magic.mime" or "magic.mgc".
#10
humm... actually this might be a won't fix since http://us3.php.net/manual/en/function.finfo-open.php says:
#11
I'm now starting to think that it would be best to have a setting that specifies the path to the magic database. We could use the one that ships with mimedetect as the default value. Thoughts?
#12
Drewish, I think this is a good idea. Let the users decide which file to use, leave the default set to the easiest choice, have good help text that explains to users why they would change that default value.
#13
this just adds a variable for the magic file with no form for editing it.
#14
I have this issue also. Manually uninstalled (my Drupal module uninstaller doesn't work), including database entries, reinstalled with patched and module installer won't even allow it to be activated.
Thanks!
-Brian
#15
Patch in #13 is fine, but maybe a little documentation would be nice.
#16
Installed on a "clean and sober" new install. Patch makes no difference. Uninstalling module.
#17
Do you have libmagic installed on your server ? If no try to install it and use the variable to set the path ?
#18
Changing this to a bug report, because the magic database provided by Mimedetect does not always work. You have to get your server distribution version. This patch updates the README.txt with these explanations, adds Drewish fix and the same in mimedetect.install.
Advice : first try with basic PHP, outside Drupal, if you can load the database :
<?php$magic_file = '/usr/share/file/magic';
$finfo = finfo_open(FILEINFO_MIME, $magic_file);
if (!$finfo) {
echo "Opening fileinfo database failed";
exit();
}
?>
Replace '/usr/share/file/magic' by the correct path if it's different.
#19
In the docs of this module, will it describe to your average user how to identify the correct path to the magic file if it turns out that the default doesn't work upon install? Might reduce the issues we all have to answer down the road. Just a thought.
#20
We can not say more that it comes with File 4.x. Installing a PHP extension is not an average user task, too, I guess ?
#21
Anyway I just added the simple PHP test in the README.txt.
#22
I tried the patch from guix in #21. It has a minor bug - there is an extra space in the source file line to be removed that prevented the patch from working. Instead of
$magic_file = drupal_get_path('module', 'mimedetect') . '/magic';
(extra space between the period and quote right before /magic) it should be
$magic_file = drupal_get_path('module', 'mimedetect') .'/magic';
At least that's how I got it to apply.
#23
Terrific work - patch applied with the mad as listed in #22 - thanks much!
#24
The new docs are a great addition. I've done a little clean up on the to wrap long lines and get the punctuation to match the rest of the file.
#25
committed to HEAD and DRUPAL-6--1
#26
Automatically closed -- issue fixed for 2 weeks with no activity.
#27
The documentation mentions to add a setting in settings.php like
'mimedetect_magic' => '/usr/share/file/magic'In my case, I had to change it to:
'mimedetect_magic' => '/usr/share/file/magic.mime'Notice the .mime extension! This apparently needed on my linux debian VPS.
Also, I had to overcome an open_basedire restriction by editing the vhost.conf to add /usr/share/fil.
#28
subscribe