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
Release: 2024-11-08 05:46:01
Original
357 people have browsed it

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));
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template