PHP's Fileinfo Function Returns an Error Message: 'Undefined Function'
When attempting to retrieve the mime content type in PHP, an error message appears, indicating that the 'finfo' class or 'finfo_open' function is not recognized. The accompanying code does not seem to work either.
Root of the Issue:
The cause of this issue lies in the PHP configuration. Specifically, the fileinfo extension is not properly enabled.
Resolution:
-
Locate the php.ini File: Find the php.ini configuration file on your system. Its location varies depending on the operating system and PHP version.
-
Enable the Fileinfo Extension: Search for a line similar to "extension=fileinfo.so" (Windows) or "extension=php_fileinfo.dll" (Unix/Linux). If this line is present, uncomment it by removing the semicolon.
-
Restart PHP: Once the extension is enabled, restart your PHP web server or process to load the new configuration.
-
Retest the Code: The fileinfo function should now work as intended. Retest your code and verify that it can determine the mime content type successfully.
The above is the detailed content of Why is PHP's Fileinfo Function Returning an 'Undefined Function' Error?. 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