在 Windows PHP 5.3.5 中使用 php_fileinfo.dll 和 finfo_open
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5108758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using php_fileinfo.dll and finfo_open in Windows PHP 5.3.5
提问by tomfumb
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...
我在使用 PHP 5.3.5 和 IIS 6 的 Windows Server 2003 上运行的 PHP 脚本中调用 finfo_open 时遇到问题。调用总是返回致命错误:调用未定义的函数 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.phpdidn'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/Fileinfothat "As of PHP 5.3.0 this extension is enabled by default". What's going on?
通过一点阅读,我知道默认情况下 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 起,此扩展默认启用”。这是怎么回事?
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).
此问题在测试服务器上。在我的本地机器上,我有 xampp 和 PHP 5.3.1 并且调用工作正常,所以我也尝试在测试时将 php_fileinfo.dll 从本地复制到 php\ext 但这也没有任何区别(我知道版本是不同,但我读到 5.3 是重要的一点)。
Any advice on this would be much appreciated!
对此的任何建议将不胜感激!
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $filepath);
回答by hakre
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:
请参阅fileinfo 使用和安装说明:
Windows users must include the bundled php_fileinfo.dll DLL file in php.ini to enable this extension.
Windows 用户必须在 php.ini 中包含捆绑的 php_fileinfo.dll DLL 文件才能启用此扩展。
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.
例如,该 DLL 文件与 PHP 5.3.6 捆绑在一起,您可以在此处找到这些文件:PHP For Windows - Binaries and sources Releases。它应该已经位于ext
PHP 安装的子目录中。如果没有从上述网站再次下载(选择您的 PHP 版本)并将其放入扩展目录。
You need to add the following line your php.ini
then to activate it:
您需要添加以下行php.ini
来激活它:
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.
这是在 Windows 下激活 PHP 扩展的标准程序。您可以在此处找到有关如何激活 PHP 扩展的更多信息:在 Windows 上安装扩展。如果您在定位 php.ini 文件时遇到问题,请参阅PHP 安装说明 - 在 Windows 系统上安装。
回答by Rodolfo Velasco
This line
这条线
extension=php_fileinfo.dll
was commented in my php.ini
so I uncommented it and then restarted my xampp server.
在我的评论中被注释掉了,php.ini
所以我取消了它的注释,然后重新启动了我的 xampp 服务器。
回答by Umar T.
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.
在按照 hakre 的建议做了之后,FileInfo 扩展仍然没有加载到我的最后,但最终我通过找出我正在修改的 php.ini 文件是错误的(位于 \MAMP\bin\php \php7.2.10) 而正确的位于 \MAMP\conf\php7.2.10。在正确的 ini 文件中启用它后,我不得不重新启动 php 服务器并关闭它。
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
注意:您可能需要将路径开头的 '\MAMP' 替换为您的网络服务器解决方案堆栈软件(例如 MAMP、WAMP、XAMP 或其他)的安装路径。由于我使用的是 MAMP,这就是为什么它出现在我的文件路径中