Codeigniter cannot correctly identify image types when uploading images _ php instance

Source: Internet
Author: User
This article mainly introduces the solution to the problem that codeigniter cannot correctly identify the image type when uploading images. This is an uncommon problem, but it will take a long time to complete the problem, for more information about how to use codeigniter to upload images, see jpg images. However, ci is always recognized as application/octet-stream, leading to upload failure, the solution is as follows:

Enable the fileinfo extension in php. ini to obtain the correct type:

The Code is as follows:


// Windows
Extension = php_fileinfo.dll

// Linux
Extension = fileinfo. so

Note: About fileinfo

The alternative function of mime_content_type () officially recommended by PHP is the Fileinfo function. PHP 5.3.0 + supports the Fileinfo support-enabled function by default. You can use finfo_open () to determine the object MIME type without any configuration. The default LAMP environment php version installed in Centos is PHP5.2.6. If it is earlier than 5.3.0, a similar error may occur: PHP Fatal error: Call to undefined function finfo_open () in .... In the previous php version, the magic_open class needs to be loaded. The fileinfo function belongs to the PECL extension, and the fileinfo PECL extension can be enabled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.