codeigniter上传图片不能正确识别图片类型问题解决方法_php实例

WBOY
Release: 2016-06-07 17:17:10
Original
754 people have browsed it

在用 codeigniter 的上传类上传图片的时候,明明是 jpg 格式图片,但是 ci 始终识别成 application/octet-stream 类型,从而导致上传失败,搜集了下资料,解决方法如下:

在 php.ini 中开启 fileinfo 扩展来获取正确的类型:

复制代码 代码如下:

//windows
extension = php_fileinfo.dll

//linux
extension = fileinfo.so

注:关于fileinfo

PHP官方推荐mime_content_type()的替代函数是Fileinfo函数。PHP 5.3.0+已经默认支持Fileinfo函数(fileinfo support-enabled),不必进行任何配置即可使用finfo_open()判断获取文件MIME类型。Centos 默认安装的LAMP环境php版本还是PHP5.2.6,低于5.3.0版本则可能出现类似错误提示:PHP Fatal error: Call to undefined function finfo_open() in…。因为之前的php版本,需要加载magic_open类,fileinfo函数属于PECL扩展,启用fileinfo PECL扩展才能

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!