YiluPHP
这家伙很懒,什么都没有留下...

经验 centos安装php缺失fileinfo.so扩展解决

浏览数 197447
centos安装php缺失fileinfo.so扩展解决

使用CI框架上传图片时报错:

在开发环境中是好好的。

网上找到这个答案,帮我解决了报这个错误的问题:

最近使用 CodeIgniter 的文件上传类时,遇到了一个问题,不管上传什么类型的文件,都会提示“The filetype you are attempting to upload is not allowed.”。实际上,我已经在文件上传类的配置中,将所需要上传的文件类型写到了 allowed_types 的配置项中。而且,通过开启 CodeIgniter 的调试信息($this->output->enable_profiler(TRUE);),发现不管上传的是什么类型的文件,CodeIgniter 都会将文件识别为 application/octet-stream 的类型。搜集了一些资料,原来原因�php的配置问题,也就是说PHP没有能力识别上传的文件的类型,自然CodeIgniter 也就无法识别文件类型了,最后把解决办法分享如下:

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

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

我的PHP没有fileinfo.so,只能重新编译安装:

1.首先检查系统是否已经安装

Configure Command =>  './configure'  '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/etc/php.d' '--with-fpm-user=www' '--with-fpm-group=www' '--enable-fpm' '--enable-opcache' '--disable-fileinfo' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir=/usr/local' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-exif' '--enable-sysvsem' '--with-curl' '--enable-mbregex' '--enable-inline-optimization' '--enable-mbstring' '--with-mcrypt' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-ftp' '--enable-intl' '--with-xsl' '--with-gettext' '--enable-zip' '--enable-soap' '--disable-ipv6' '--disable-debug'


我的出现这个说明没有安装好

如果出现以下说明安装好了:



2.执行下载包含fileinfo扩展的php安装包命令,也可以独立下载fileinfo编译安装包


wget -O php-5.5.35.tar.gz http://cn2.php.net/get/php-5.5.35.tar.gz/from/this/mirror


3.解压


tar -zxvf php-5.5.35.tar.gz


4.当前目录解压完,进入下面目录 


cd php-5.5.35/ext/fileinfo/



5.在之前已经编译安装的的php的bin目录中找到命令phpize执行生成.configure文件


本人已安装php的目录命令:

/usr/local/php/bin/phpize


6.配置、编译安装


 ./configure -with-php-config=/usr/local/php/bin/php-config


make && make install



7.修改php.ini

加入:extension=fileinfo.so


8.重启服务器,完成

service php-fpm restart




但接下来又报了一个错误:
Image processing failed. Please verify that your server supports the chosen protocol and that the path to your image library is correct
我来说说