Solution to the problem that codeigniter uploaded pictures can't correctly identify picture types

  • 2021-07-09 07:34:21
  • OfStack

When uploading pictures with the upload class of codeigniter, it is obviously an jpg format picture, but ci is always identified as application/octet-stream type, which leads to upload failure. The following data are collected, and the solutions are as follows:

Open the fileinfo extension in php. ini to get the correct type:


//windows
extension = php_fileinfo.dll //linux
extension = fileinfo.so

Note: About fileinfo

PHP officially recommends that the replacement function for mime_content_type () is the Fileinfo function. PHP 5.3. 0 + already supports the Fileinfo function by default (fileinfo support-enabled), so you can use finfo_open () to determine the MIME type of the fetch file without any configuration. Centos default installation of LAMP environment php version php is still PHP 5.2. 6, below 5.3. 0 version may appear similar error prompt: PHP Fatal error: Call ES40undefined function finfo_open () in …. Because of the previous version of php, the magic_open class needs to be loaded, and the fileinfo function belongs to the PECL extension, so the fileinfo PECL extension can be enabled


Related articles: