博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
exif_imagetype() 函数在linux下的php中不存在
阅读量:5891 次
发布时间:2019-06-19

本文共 2448 字,大约阅读时间需要 8 分钟。

1.问题,项目中上传文件使用插件时,windows上支持函数exif_imagetype(),而在linux上不支持。

2.PHP exif_imagetype的本质

PHP exif_imagetype note #1Windows users: If you get the fatal error "Fatal error:  Call to undefined function exif_imagetype()", and you have enabled php_exif.dll, make sure you enable php_mbstring.dll.  You must put mbstring before exif in the php.ini, i.e.:extension=php_mbstring.dllextension=php_exif.dllYou can check whether this has worked by calling phpinfo() and searching for exif.PHP exif_imagetype note #2If the function exif_imagetype() is not available,you can try the following workaround:if ( ! function_exists( 'exif_imagetype' ) ) {    function exif_imagetype ( $filename ) {        if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) {            return $type;        }    return false;    }}PHP exif_imagetype note #3By trial and error, it seems that a file has to be 12 bytes or larger in order to avoid a "Read error!".  Here's a work-around to avoid an error being thrown:// exif_imagetype throws "Read error!" if file is too smallif (filesize($uploadfile) > 11)    $mimetype = exif_imagetype($uploadfile);else    $mimetype = false;PHP exif_imagetype note #4Seems to give a 'Read error' warning if the size of the file is very small (2 bytes). I think this is because it needs a min 3 bytes to determine the file typePHP exif_imagetype note #5libexif can also be used to parse image info out of id3 tags:exif_read_data("mp3_with_2.4ID3TAGS, '', true, false);PHP exif_imagetype note #6After looking for hours, I found a very good source for exif related programs here: http://drewnoakes.com/code/exif/index.htmlIt lists exif specifications (pdf), a few good links to exif related stuff. The best source I have found in my quest to understand exif better for use in php based exif tools.

 

3.解决方案:

 if ( ! function_exists( 'exif_imagetype' ) ) {
          // $currFile = $file['tmp_name'];           list($width, $height, $type2, $attr) = getimagesize($file['tmp_name']);            $type = $type2;           // function exif_imagetype ($currFile) {
          //   if ( ( list($width, $height, $type2, $attr) = getimagesize($currFile) ) !== false ) {
          //       // return $type;           //     $type = $type2;           //   }           //   return false;           // }         }else{
           // $type = exif_imagetype($src);           $type = exif_imagetype($file['tmp_name']);         }

 

转载地址:http://geysx.baihongyu.com/

你可能感兴趣的文章
《OSPF和IS-IS详解》一1.4 互联网的诞生
查看>>
程序员如何做出“不难看”的设计
查看>>
《UNIX网络编程 卷1:套接字联网API(第3版)》——1.11 64位体系结构
查看>>
中国可能放弃 Windows 完全转用 Linux 吗?
查看>>
《Cisco ASA设备使用指南(第3版)》一2.11 Cisco ASA 5555-X型
查看>>
Apache Twill —— 分布式应用开发框架
查看>>
Google 微软达成专利和解,协议包含 Android
查看>>
《Adobe Acrobat X中文版经典教程》—第2章复 习
查看>>
《Linux/UNIX OpenLDAP实战指南》——导读
查看>>
《精通VMware vSphere 6》——第2章 规划与安装 VMware ESXi 2.1规划VMware vSphere部署...
查看>>
如何安装体验 Ubuntu on Windows
查看>>
《移动App测试的22条军规》——军规5 关注用户体验
查看>>
《编程珠玑(第2版•修订版)》—第1章1.1节一次友好的对话
查看>>
《 营销数据科学: 用R和Python进行预测分析的建模技术》——第3章 锁定目标客户...
查看>>
JQuery入门(2)
查看>>
[小白技巧]在Ubuntu 14.04中,如何从Unity启动器上移除盘符图标
查看>>
POI导出JavaWeb中的table到excel下载
查看>>
只有数据分析师才能看懂的十大吐槽
查看>>
《无人机DIY》——4 制作四轴直升机I:选择 机身 
查看>>
《单页Web应用:JavaScript从前端到后端》——1.3 精心编写的单页应用的用户效益...
查看>>