在 Windows PHP 5.3.5 中使用 php_fileinfo.dll 和 finfo_open
我在使用 PHP 5.3.5 和 PHP 在 Windows Server 2003 上运行的 PHP 脚本中调用 finfo_open 时遇到问题。 IIS 6。调用总是返回致命错误:调用未定义的函数 finfo_open() in...
通过一点阅读,我知道 Windows PHP 安装中默认不包含 fileinfo 功能,尽管我没有尝试让它工作。注释 #3 中的说明: http://www.php.net/manual /en/fileinfo.installation.php 没有帮助,这是我能找到的最官方的解释。网上有很多关于需要 mime_magic dll 的信息,但从 5.3 开始似乎不再需要它。此外,我在 http://pecl.php.net/package/Fileinfo 上读到“从 PHP 5.3.0 开始,此扩展默认启用”。这是怎么回事?
此问题出现在测试服务器上。在我的本地计算机上,我有 xampp 和 PHP 5.3.1 并且调用工作正常,因此我还尝试在测试时将 php_fileinfo.dll 从本地复制到 php\ext,但这也没有任何区别(我知道版本是不同,但我读到 5.3 是重要的一点)。
任何对此的建议将不胜感激!
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $filepath);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您已经接近完成它,只缺少一些小配置。
请参阅fileinfo 使用和安装说明:
例如,该 DLL 文件与 PHP 5.3.6 捆绑在一起,您可以在此处找到这些文件: PHP For Windows - Binaries and来源发布。它应该已经位于 PHP 安装的
ext
子目录中。如果没有,请从上述网站重新下载(选择您的 PHP 版本)并将其放入扩展目录中。您需要将以下行添加到
php.ini
然后激活它:这是在 Windows 下激活 PHP 扩展的标准过程。您可以在此处找到有关如何激活 PHP 扩展的更多信息:在 Windows 上安装扩展。如果您无法找到 php.ini 文件,请参阅 PHP 安装说明- 在 Windows 系统上安装。
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:
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: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.
这行代码
在我的 php.ini 中被注释掉了,所以我取消了它的注释,然后重新启动了我的 xampp 服务器。
This line
was commented in my
php.ini
so I uncommented it and then restarted my xampp server.在按照 hakre 的建议进行操作后,FileInfo 扩展在我这边仍然没有加载,但最终我发现我正在修改的 php.ini 文件是错误的(位于 \MAMP\bin\php ),从而解决了这个问题\php7.2.10),而正确的位置位于 \MAMP\conf\php7.2.10。
在正确的 ini 文件中启用它后,我必须重新启动 php 服务器,然后它就可以工作了。
注意:您可能需要将路径开头的“\MAMP”替换为安装 Web 服务器解决方案堆栈软件(例如 MAMP、WAMP、XAMP 或其他)的路径。由于我使用的是 MAMP,这就是它出现在我的文件路径中的原因
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