Vladimir Altuhov
Vladimir Altuhov

Reputation: 21

Zend FR finfo error Warning: string extension `B' invalid

I have problems after updating Zend FR to 1.11

Mimetype file checking generates:

Warning: string extension `B' invalid

It looks like cause of problems the string in the Zend_Validate_File_MimeType

$finfo = finfo_open(FILEINFO_MIME_TYPE, $file);

I have created simple test case

$finfo = finfo_open(FILEINFO_MIME_TYPE, '/usr/share/misc/magic');
echo finfo_file($finfo, PUBLIC_HTML_PATH . '/images/missing.png');
finfo_close($finfo);

And i got same error :(

finfo_open(FILEINFO_MIME_TYPE, '/usr/share/misc/magic'); //generates: Warning: string extension `B' invalid.

My OS: Kbuntu 10.10

Where am i wrong?

Upvotes: 2

Views: 1612

Answers (4)

user1100149
user1100149

Reputation: 266

I had this error in Laravel (minus Zend FR, of course). Running PHP 5.3.21 on a Windows box with IIS.

Finding very little info online I was close to giving up. It worked initially when I followed instructions in the comments on PHP.net, which were basically to add fileinfo.dll to your PHP installation, and to also download the relevant magic files and point an environment variable to them.

There was some initial confusion until I realised I didn't actually have php_fileinfo.dll, so as well as adding it to the php.ini file, I had to download the file itself and add it to my ext directory.

Now what really had me stuck, was that it worked initially. The next day it didn't. To cut a long story short, it didn't need the environment variable, MAGIC. The reason this had me stuck, is because I had tried every possible scenario, but once the environment variable had been set, it had been set. And I had to restart the Windows server after removing it, to unset it. Once I did this it worked perfectly.

Upvotes: 0

acorncom
acorncom

Reputation: 5955

Ran into the same error message ("Warning: string extension w' invalid in Command") as Mike Purcell, but the fix for it was different.

On our servers we had a /usr/share/misc/magic and a /usr/share/misc/magic.mgc file. The magic.mgc file had been compiled from the magic file, but PHP still wasn't happy talking directly to the /usr/share/misc/magic file (we'd shifted to that file as part of debugging that the magic.mgc file needed updating).

The fix for us was changing our putenv line back to the magic.mgc file:

putenv('MAGIC=/usr/share/misc/magic.mgc');

Then, magic-ally :-) , the whole mime-type detection system started working again.

Upvotes: 2

Chris DaMour
Chris DaMour

Reputation: 4020

Depending on your PHP version the magic format may be updated. This is documented in a note at http://php.net/manual/en/function.finfo-open.php

run php -v to see your version

I got the same error when pointing to an older magic file in our source tree, and resolved it when pointing to a newer magic file from my current linux distro

Upvotes: 1

Mike Purcell
Mike Purcell

Reputation: 19999

This may not pertain to your EXACT issue, but it did resolve the issue I was having which resulted in a very similar error message: "Warning: string extension w' invalid in Command".

For us, we have a heterogenous setup where some servers are still running php 5.2 and others running php 5.3. On the 5.2 boxes the magic file resides in /usr/share/file/magic, but on the 5.3 boxes the file resides in the default path of /usr/share/misc/magic. Apparently someone tried to reconcile these path differences by symlinking the 5.2 path so the codebase could be php version agnostic. But according to some comments posted on PHP site regarding symlinks to the magic file, it will result in unexpected behavior, which of course was resulting in the aforementioned error message.

So be sure the path you are passing is to the actual magic file, and not a symlink, and see if that resolves your issue.

Upvotes: 1

Related Questions