Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using php_fileinfo.dll and finfo_open in Windows PHP 5.3.5

I'm having trouble calling finfo_open in a PHP script running on Windows Server 2003 with PHP 5.3.5 & IIS 6. The call always returns Fatal error: Call to undefined function finfo_open() in...

Through a little reading I know that fileinfo functionality is not included by default in the windows PHP installation, though nothing I try gets it working. The instructions in comment #3 here: http://www.php.net/manual/en/fileinfo.installation.php didn't help, and that's the most official looking explanation I can find. There's lots of information about needing the mime_magic dll on the web but it seems like this is no longer required as of 5.3. Furthermore, I have read on http://pecl.php.net/package/Fileinfo that "As of PHP 5.3.0 this extension is enabled by default". What's going on?

This issue is on a testing server. On my local machine I have xampp and PHP 5.3.1 and the call works fine, so I also tried copying the php_fileinfo.dll from local to php\ext on testing but this also didn't make any difference (I know that versions are different, but I read that the 5.3 is the important bit).

Any advice on this would be much appreciated!

    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    $mime = finfo_file($finfo, $filepath);
like image 978
tomfumb Avatar asked Feb 24 '11 18:02

tomfumb


People also ask

What is Fileinfo extension PHP?

FileInfo functions module can try to guess a content type and encoding of a file by looking for certain magic byte sequences at a specific position within a file. While it's not a bulletproof approach, the heuristics used to do a very good job. Before PHP 5.3.

What is Finfo_open?

PHP - FileInfo open() Function The finfo_open() function can create a new fileinfo resource.


1 Answers

You're already close to get it done, only some little configuration is missing on your end.

Please see the fileinfo usage and installation instructions:

Windows users must include the bundled php_fileinfo.dll DLL file in php.ini to enable this extension.

That DLL file is bundeled with PHP 5.3.6 for example, you can find the files here: PHP For Windows - Binaries and sources Releases. It should be already located in the ext subdirectory of your PHP installation. If not download it again from the said website (choose your PHP version) and place it into the extension directory.

You need to add the following line your php.ini then to activate it:

extension=php_fileinfo.dll

That's the standard procedure to activate a PHP extension under windows. You can find more information about how to actiave a PHP extension here: Installation of extensions on Windows. If you have problems to locate the php.ini file, please refer to the PHP installation instructions - Installation on Windows systems.

like image 97
hakre Avatar answered Sep 21 '22 18:09

hakre