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!