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 her开发者_JAVA百科e: 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);
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.
This line
extension=php_fileinfo.dll
was commented in my php.ini
so I uncommented it and then restarted my xampp server.
After doing what hakre suggested, the FileInfo extension was still not loaded at my end, but then eventually I solved it by figuring out that the php.ini file I was modifying was the wrong one (that was located at \MAMP\bin\php\php7.2.10) whereas the correct one was located at \MAMP\conf\php7.2.10. After enabling it in the correct ini file, I had to restart the php server and off it worked.
NOTE: You might have to replace '\MAMP' from the start of the path with the path where your web-server solution stack software (e.g. MAMP, WAMP, XAMP or else) is installed. Since I was using MAMP that's why its present in my file path
精彩评论