PHP fileinfo 是未定义的函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3579072/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:17:42  来源:igfitidea点击:

PHP fileinfo is undefined function

phpmime-typesundefined-function

提问by Jobynad

Whenever I try to get the mime content type from php, it echos:

每当我尝试从 php 获取 mime 内容类型时,它都会回应:

Fatal error:Class 'finfo' not found in /home/jobynadel/finadel.com/video/finfo.phpon line 4

致命错误:在第4行的/home/jobynadel/finadel.com/video/finfo.php 中找不到“finfo”类

or

或者

Fatal error:Call to undefined function finfo_open in /home/jobynadel/finadel.com/video/finfo.phpon line 4

致命错误:在第4行调用/home/jobynadel/finadel.com/video/finfo.php 中未定义的函数 finfo_open

I just can't figure it out!

我就是想不通!

The code I am using is:

我正在使用的代码是:

$file_info = new finfo(FILEINFO_MIME_TYPE);
// See constant value http://php.net/manual/en/fileinfo.constants.php#113687 
$mime_type = $file_info->buffer(file_get_contents($file));

回答by jdehaan

Have a look at your php.ini file and check that the fileinfo.soor php_fileinfo.dllis activated (depending on your platform and version).

查看您的 php.ini 文件并检查fileinfo.sophp_fileinfo.dll是否已激活(取决于您的平台和版本)。

There should be a line similar to

应该有一条类似于

extension=fileinfo.so

in your php.ini file

在你的 php.ini 文件中

回答by binhhoang18

If you using XAMPP, you enable extension=php_fileinfo.dllin php.ini

如果您使用 XAMPP,则extension=php_fileinfo.dll在 php.ini 中启用

回答by Jordan Running

What version of PHP do you have? PHP 5.3.0 and later have Fileinfo built in, but on Windows you must enable it manually in your php.ini. You can find further information in the documentation.

你有什么版本的PHP?PHP 5.3.0 及更高版本内置了 Fileinfo,但在 Windows 上,您必须在php.ini. 您可以在文档中找到更多信息。

回答by Vikrant Ramteke

If you are using WAMP then Go to PHP extensions and enbale PHP_fileinfoand restart all serverices.

如果您使用的是 WAMP,则转到 PHP 扩展并启用 PHP_fileinfo并重新启动所有服务器。

回答by Peter Moses

Windows users: just edit php.iniand uncomment this line:

Windows 用户:只需编辑php.ini并取消注释此行:

extension=php_fileinfo.dll

I.e. remove the preceding semicolon from

即从中删除前面的分号

;extension=php_fileinfo.dll

Remember to restart Apache for new php.inito take effect.

记得重启 Apache 使新的php.ini生效。

回答by Alan Bellows

For those have had it working fine, but then this error appears:

对于那些工作正常的人,但随后出现此错误:

Some hosting providers (e.g., Dreamhost) allow customers to override default PHP settings in a configuration file, often with a path something like:

一些托管服务提供商(例如 Dreamhost)允许客户覆盖配置文件中的默认 PHP 设置,通常使用类似于以下内容的路径:

~/.php/5.4/phprc

~/.php/5.4/phprc

That version number in the path can be a problem if you upgrade PHP (or it is upgraded on your behalf). Any custom settings from the prior version, including one enabling the fileinfo extension, will be missing in the newer version. Usually you can just copy the config file to the appropriate new config directory and restart the server.

如果您升级 PHP(或代表您升级),路径中的版本号可能会成为问题。先前版本中的任何自定义设置,包括启用文件信息扩展的设置,都将在较新版本中丢失。通常,您只需将配置文件复制到相应的新配置目录并重新启动服务器即可。

回答by lalithkumar

I had this same issue with PHP.I did the following steps:

我在 PHP 上遇到了同样的问题。我做了以下步骤:

 - make sure that the fileinfo extension is already installed if you are using < PHP 5.3.0.

 - Then you have to add in php.ini ;extension=fileinfo.so or
   ;extension=php_fileinfo.dll

 -  If you want to uncomment remove the semicolon(;)
   extension=fileinfo.so or extension=php_fileinfo.dll

Then save and restart your web server.

然后保存并重新启动您的 Web 服务器。