Jump to content

Install Fileinfo


Recommended Posts

I'm having a bear of a time installing the Fileinfo module.

Here is my test script:
[code]
<?php
  // fileinfo_test.php
  $fi = finfo_open(FILEINFO_MIME);
  echo (($out = finfo_file($fi, 'package.xml')) === false ? 'false' : $out) . "\n";
  finfo_close($fi);
?>
[/code]

Here is the error I get:
[b]Fatal error: Call to undefined function: finfo_open() in /home/webview/public_html/test/fileinfo_test.php on line 3[/b]

As root:
[code]
> find / -name "fileinfo.so"
/usr/local/lib/php/extensions/no-debug-non-zts-20020429/fileinfo.so

> find / -name "php.ini"
/scripts/php.ini
/usr/lib/php.ini
/usr/local/Zend/etc/php.ini
/usr/local/cpanel/3rdparty/etc/php.ini
/usr/local/cpanel/3rdparty/lib/php.ini
/usr/local/lib/php.ini
[/code]

Now I have added into every single php.ini the following:
[code]
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
;  extension=modulename.extension
;
; For example, on Windows:
;
;  extension=msql.dll
;
; ... or under UNIX:
;
;  extension=msql.so
;
; Note that it should be the name of the module only; no directory information
; needs to go here.  Specify the location of the extension with the
; extension_dir directive above.

mime_magic.magicfile = "/usr/share/file/magic.mime"
extension=fileinfo.so
[/code]

I then restart the apache server and my script still fails.

Any ideas?
Link to comment
Share on other sites

I swear I did this once before, but perhaps it was in the wrong php.ini file; mental note: make sure you edit php.ini that is displayed in phpinfo().

I added:
[code]; Directory in which the loadable extensions (modules) reside.
extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20020429/" ;[/code]

Restarted the server and now phpinfo() is reporting fileinfo support.

However, now I get the errors:
[b]Warning: finfo_open() [function.finfo-open]: Failed to load magic database at '/usr/share/misc/magic'. in /home/webview/public_html/test/fileinfo_test.php on line 3

Warning: finfo_file(): supplied argument is not a valid file_info resource in /home/webview/public_html/test/fileinfo_test.php on line 4

Warning: finfo_close(): supplied argument is not a valid file_info resource in /home/webview/public_html/test/fileinfo_test.php on line 5[/b]

Anyways, I'm sure I'll figure it out shortly, just posting in case anyone runs into the same problem in the future.
Link to comment
Share on other sites

If I call finfo_open like so:
  $fi = finfo_open(FILEINFO_MIME, "/usr/share/file/magic");

I receive no error.  If I leave off the second argument, I get the errors in the above post.

Now, looking at http://www.php.net/finfo_open, the following applies to the second argument:
[i]Name of a magic database file, usually something like /path/to/magic.mime. If not specified, MAGIC environment variable is used. If this variable is not set neither, /usr/share/misc/magic is used. .mime and/or .mgc is added if appropriate.[/i]

Now I've edited .bash_profile as both root and the regular user to have the lines:
[code]MAGIC=/usr/share/file/magic
export MAGIC[/code]

Logged everything out, went back in, and restarted the apache server.  Checking env at the command prompt reveals that MAGIC=/usr/share/file/magic.  The apache server is not running as nobody, but as the user whose .bash_profile I modified.

For the life of me I can't figure out why it's not using the default value I've specified in the MAGIC environment variable.

Any help?
Link to comment
Share on other sites

Thanks for the response wildteen.  That was done and it was during that process that the [i]/usr/local/lib/php/extensions/no-debug-non-zts-20020429/[/i] directory was created.

However I still had to go in and edit php.ini to include the DSO as an extension.  Everything works just fine now except when calling [b]finfo_open[/b] I have to pass the magic file to use, whereas on the old server I didn't.  That was the last thing I was trying to fix and I finally gave up and said, "Screw it."  I don't call it very often and I'm passing the path to the magic file as a constant defined in a central location so if I ever have to move hosts or change it, it will be a quick process.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.