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

cultiv8 - September 13, 2008 - 17:59

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

matt_paz - September 17, 2008 - 20:23

I have the same experience on D6 using Windows/IIS

#3

Zach Harkey - September 23, 2008 - 12:32

Reporting same problem here. Been troubleshooting off and on for days.

#4

seaneffel - September 23, 2008 - 14:18
Title:Can't install magic file» Fileinfo could not load the magic file

Changed name to better reflect the issue we're having. That magic file isn't so magical, now is it.

#5

nnn - September 29, 2008 - 04:10

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

Zach Harkey - September 30, 2008 - 04:38

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

Yorirou - November 28, 2008 - 13:37
Version:6.x-1.0-beta1» 5.x-1.0
Status:active» needs review

I wrote an oneliner patch to fix this issue.

AttachmentSize
fileinfo.patch 723 bytes

#8

drewish - March 16, 2009 - 20:40
Version:5.x-1.0» 6.x-1.x-dev

here's the patch for D6.

AttachmentSize
mimedetech_306217.patch 1.08 KB

#9

drewish - March 16, 2009 - 20:49
Status:needs review» needs work

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

drewish - March 16, 2009 - 21:29

humm... actually this might be a won't fix since http://us3.php.net/manual/en/function.finfo-open.php says:

magic_file

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.

#11

drewish - April 15, 2009 - 19:29

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

seaneffel - April 22, 2009 - 14:39

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

drewish - May 9, 2009 - 17:45
Version:6.x-1.x-dev» 7.x-1.x-dev
Status:needs work» needs review

this just adds a variable for the magic file with no form for editing it.

AttachmentSize
mimedetect_306217.patch 718 bytes

#14

brianbrown - June 16, 2009 - 18:24

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

guix - June 18, 2009 - 11:17
Status:needs review» reviewed & tested by the community

Patch in #13 is fine, but maybe a little documentation would be nice.

#16

brianbrown - June 18, 2009 - 14:19

Installed on a "clean and sober" new install. Patch makes no difference. Uninstalling module.

#17

guix - June 18, 2009 - 15:31
Status:reviewed & tested by the community» needs work

Do you have libmagic installed on your server ? If no try to install it and use the variable to set the path ?

#18

guix - June 19, 2009 - 12:12
Category:support request» bug report
Status:needs work» needs review

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.

AttachmentSize
mimedetect-306217-18.patch 2.82 KB

#19

seaneffel - June 19, 2009 - 13:24

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

guix - June 20, 2009 - 01:27

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

guix - June 20, 2009 - 01:36

Anyway I just added the simple PHP test in the README.txt.

AttachmentSize
mimedetect-306217-20.patch 3.3 KB

#22

mjhammel - July 27, 2009 - 23:21

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

bcobin - September 12, 2009 - 14:14
Version:7.x-1.x-dev» 6.x-1.x-dev

Terrific work - patch applied with the mad as listed in #22 - thanks much!

#24

drewish - September 12, 2009 - 17:02

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.

AttachmentSize
mimedetect_306217.patch 3.09 KB

#25

drewish - September 12, 2009 - 17:11
Status:needs review» fixed

committed to HEAD and DRUPAL-6--1

#26

System Message - September 26, 2009 - 17:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#27

morningtime - October 30, 2009 - 11:08
Status:closed» active

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

rmiddle - November 17, 2009 - 04:34

subscribe

 
 

Drupal is a registered trademark of Dries Buytaert.