Home >Backend Development >PHP Tutorial >Why is PHP Throwing an 'Undefined Function finfo' Error When Retrieving MIME Content Type?

Why is PHP Throwing an 'Undefined Function finfo' Error When Retrieving MIME Content Type?

DDD
DDDOriginal
2024-11-08 05:46:01370browse

Why is PHP Throwing an

PHP: Undefined Function finfo

When attempting to retrieve the MIME content type, an error occurs indicating that the class 'finfo' or the function 'finfo_open' is undefined. This error originates from the code snippet below:

$file_info = new finfo(FILEINFO_MIME_TYPE);
$mime_type = $file_info->buffer(file_get_contents($file));

Solution

The root cause of this error lies in the PHP configuration file (php.ini). Ensure that the fileinfo extension is properly enabled. Locate the following line in your php.ini file:

extension=fileinfo.so

If this line is commented out (preceded by a semicolon), uncomment it to activate the fileinfo extension.

Additional Notes

Depending on your operating system and PHP version, the extension file may be named php_fileinfo.dll instead of fileinfo.so. Adjust the line in php.ini accordingly.

After making these changes, restart your PHP server for the modifications to take effect.

The above is the detailed content of Why is PHP Throwing an 'Undefined Function finfo' Error When Retrieving MIME Content Type?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn