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.
Comment | File | Size | Author |
---|---|---|---|
#43 | mimedetect-magic.patch | 1.19 KB | likewhoa |
#34 | readme.patch | 3.49 KB | seaneffel |
#24 | mimedetect_306217.patch | 3.09 KB | drewish |
#21 | mimedetect-306217-20.patch | 3.3 KB | GuillaumeDuveau |
#18 | mimedetect-306217-18.patch | 2.82 KB | GuillaumeDuveau |
Comments
Comment #1
rj CreditAttribution: rj commentedI 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.
Comment #2
matt_paz CreditAttribution: matt_paz commentedI have the same experience on D6 using Windows/IIS
Comment #3
Zach Harkey CreditAttribution: Zach Harkey commentedReporting same problem here. Been troubleshooting off and on for days.
Comment #4
seaneffel CreditAttribution: seaneffel commentedChanged name to better reflect the issue we're having. That magic file isn't so magical, now is it.
Comment #5
nnn CreditAttribution: nnn commentedI 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.
Comment #6
Zach Harkey CreditAttribution: Zach Harkey commentedTried 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.
Comment #7
tamasd CreditAttribution: tamasd commentedI wrote an oneliner patch to fix this issue.
Comment #8
drewish CreditAttribution: drewish commentedhere's the patch for D6.
Comment #9
drewish CreditAttribution: drewish commentedactually 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".
Comment #10
drewish CreditAttribution: drewish commentedhumm... actually this might be a won't fix since http://us3.php.net/manual/en/function.finfo-open.php says:
Comment #11
drewish CreditAttribution: drewish commentedI'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?
Comment #12
seaneffel CreditAttribution: seaneffel commentedDrewish, 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.
Comment #13
drewish CreditAttribution: drewish commentedthis just adds a variable for the magic file with no form for editing it.
Comment #14
brianbrown CreditAttribution: brianbrown commentedI 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
Comment #15
GuillaumeDuveauPatch in #13 is fine, but maybe a little documentation would be nice.
Comment #16
brianbrown CreditAttribution: brianbrown commentedInstalled on a "clean and sober" new install. Patch makes no difference. Uninstalling module.
Comment #17
GuillaumeDuveauDo you have libmagic installed on your server ? If no try to install it and use the variable to set the path ?
Comment #18
GuillaumeDuveauChanging 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 :
Replace '/usr/share/file/magic' by the correct path if it's different.
Comment #19
seaneffel CreditAttribution: seaneffel commentedIn 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.
Comment #20
GuillaumeDuveauWe can not say more that it comes with File 4.x. Installing a PHP extension is not an average user task, too, I guess ?
Comment #21
GuillaumeDuveauAnyway I just added the simple PHP test in the README.txt.
Comment #22
mjhammel CreditAttribution: mjhammel commentedI 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.
Comment #23
bcobin CreditAttribution: bcobin commentedTerrific work - patch applied with the mad as listed in #22 - thanks much!
Comment #24
drewish CreditAttribution: drewish commentedThe 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.
Comment #25
drewish CreditAttribution: drewish commentedcommitted to HEAD and DRUPAL-6--1
Comment #27
Anonymous (not verified) CreditAttribution: Anonymous commentedThe 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.
Comment #28
rmiddle CreditAttribution: rmiddle commentedsubscribe
Comment #29
jacobson CreditAttribution: jacobson commentedJust for clarification. The documentation in the patch file says to add the following line to the settings.php file:
On my system, a leading slash was required before "usr" to make the module work. I too had to add .mime to the file name.
Comment #30
annajonna CreditAttribution: annajonna commentedDid some research on the two files on my server. Btw an Ubuntu (8.04) Long Term Support release.
The result is that those two files are very different in size.
Both files are text files. I would suspect that /usr/share/file/magic would support many more filetypes than the smaller file /usr/share/file/magic.mime .
There are also binary versions of those files and they are even bigger.
Comment #31
Th30philus CreditAttribution: Th30philus commentedRunning on Drupal 6.16, I applied this patch to MimeDetect 1.2 (and 1.x-dev) (and specified the mimedetect_magic variable in settings.php (both with and without the .mime extension)), but I still get the error. The simple test from comment 18 works, but MimeDetect can't load the magic file. Any thoughts on a fix?
Comment #32
Th30philus CreditAttribution: Th30philus commentedSolved. I copied and pasted the variable assignment from the README, but as pointed out in comment 29, the README lacks the leading "/". This fixed it for me. I did not need to add the .mime, BTW.
Comment #33
seaneffel CreditAttribution: seaneffel commentedI added the following lines to my settings.php as described in the readme.txt file in the module directory. I too had to add a slash in front of the "usr/..." path in order for my server to detect this magic file, as seen below.
The key to good docs here is referencing some link to what this PHP extension is, and noting for new Drupal site admins that means a conversation with their web host if it is not working. I agree with the comment in #20 above, but suggesting a place to start for troubleshooting is a nice effort for users.
Here are the verbose changes to the docs I suggest, I'm working on a patch file - though I don't have a lot of skill in creating those yet. BRB.
Comment #34
seaneffel CreditAttribution: seaneffel commentedBang. That, folks, is my first Drupal patch. Feels good.
Hope it works.
Maybe these changes are helpful to new users who don't know how to administer their servers. I teach Drupal classes and I see how frustrated users get when their docs don't speak their language - And, of course, how frustrated module maintainers are when their issue queues fill up.
Comment #35
drewish CreditAttribution: drewish commentedseaneffel, thanks, I added some line wrapping and committed this to HEAD and DRUPAL-6--1.
Comment #37
chalkboard CreditAttribution: chalkboard commentedOn centos 5.6 and 6 at least, the right "magic" file seems to be
/usr/share/misc/magic.mgc
so in drupal/sites/default/settings.php :
$conf = array(
'mimedetect_magic' => '/usr/share/misc/magic.mgc',
);
should solve the problem
Comment #38
seaneffel CreditAttribution: seaneffel commentedI fricking -hate- that magic file. If I could, I would either:
1. Make it vanish into thin air.
2. Put it in a box and saw it in half.
Seriously, if there were a single file in all of Drupal that I could nominate as the least magical - in fact sucks the magic out of the room - I would choose that one.
Comment #39
mlconnor CreditAttribution: mlconnor commentedI'm running Redhat and the setup needs to be
$conf = array(
'mimedetect_magic' => '/usr/share/misc/magic.mgc',
);
Comment #40
abi2 CreditAttribution: abi2 commentedI am still having this problem even after applying the patches.
I did a test outside drupal using the following php code:
$fp = finfo_open(FILEINFO_MIME);if (!$fp) { echo "Failed to open database\n"; exit(1);}echo $fp->file(__FILE__);
I got this error:
Warning: finfo_open() [function.finfo-open]: Failed to load magic database at '/usr/share/file/magic'. in /home/site/public_html/test.php on line 3
Opening fileinfo database failed
Comment #41
tobiberlinI used the php file mentioned in README to find out if I defined the right path. Here this is the result:
Comment #42
pmaguniaFor me, the finfo_open function doesnt take a second parameter (https://bugs.php.net/bug.php?id=53452) The magic file is built into php so it doesnt need to be specificied (at least in php 5.3.)
Any ways I got it to work after changing line 55 in the install file to the following (remove the php brackets for you newbies)
if (!$finfo = @finfo_open(FILEINFO_MIME)) {
You will also need to change it in the module file if you are going the finfo route rather than the file binary
Comment #43
likewhoa CreditAttribution: likewhoa commented#42 WFM using php-5.3.10
attached is a patch to make these changes apply to -dev version and should only be used on systems with >=php-5.3.
Comment #44
caiosba CreditAttribution: caiosba commentedFor Debian Squeeze, I had to add the following to settings.php:
And it went well. No patches needed.
Comment #45
aasarava CreditAttribution: aasarava commentedIf you're on PHP >= 5.3 where the magic file is built into finfo_open, you can resolve the "could not load the magic file" error by adding the following to your settings.php file:
Comment #46
yogeshchaugule8 CreditAttribution: yogeshchaugule8 commentedwas having same issue with Drupal 6, #44 solved.
Yogesh
Comment #47
Justin Freeman CreditAttribution: Justin Freeman commented#45 PHP >= 5.3 solves problem Drupal 6.
Comment #48
dgtlmoon CreditAttribution: dgtlmoon commentedThe $conf edit worked for me, but I still think the patch is a better approach
Comment #49
esbon CreditAttribution: esbon commentedHi, thanks for the patch, but it did not work for me on D7 PHP 5.3.23 I have question though. Is PHP's fileinfo extension obsolete?
Comment #50
esbon CreditAttribution: esbon commentedSo the patch on #43 and the configuration on #45 are correct. In my case I had to delete fileinfo.ini from PHP.D directory so PHP did not try to load it giving me errors. This is working with PHP 5.3 Thanks everyone for posting this!
Comment #51
mattwmc CreditAttribution: mattwmc commentedHaving an issue getting this to work with Domain.
In settings.php, the coding seems to conflict with the two.
If I have don't have either one at the bottom, one won't work.
For instance if mimedetect is above domain, mimedetect won't work.
Likewise, if domain is above mimedetect, my top level subdomains redirect to the main domain (i've tried an htaccess redirect, but doesn't work).
Any ideas how to get the two codes to work correctly? Thanks.
Update: Got it to work.
Looks like it was an issue with memcache as well.
This seems to be working:
Comment #52
maximpodorov CreditAttribution: maximpodorov commentedThis solution is quite fragile. The module must allow to select the way of mime type detection in settings form which must be shown always (it is hidden now if fileinfo is used). And the default way must be file_get_mimetype(). This will allow users to install the module and select the appropriate way for them. The settings form must allow to set 'mimedetect_magic' variable by hand, not by changing settings.php only.
Comment #53
manuel.adanNew README.txt version (just committed) clarifies how to solve PHP fileinfo issues. As @mattwcm mentioned:
$conf['mimedetect_magic'] = '';
will let fileinfo extension relies on system or PHP builtin magic information.