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

2.PHP exif_imagetype的本质

PHP exif_imagetype note #
Windows 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.dll
extension=php_exif.
dll

You can check whether this has worked by calling phpinfo() and searching for exif.
PHP exif_imagetype note #
If 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 #
By 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 small
if (filesize($uploadfile) > 11)
$mimetype = exif_imagetype($uploadfile);
else
$mimetype = false;
PHP exif_imagetype note #4
Seems 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 type
PHP exif_imagetype note #5
libexif 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 #6
After looking for hours, I found a very good source for exif related programs here: http://drewnoakes.com/code/exif/index.html
It 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']);
        }

最新文章

  1. Java EE之数据库连接与插入
  2. 关于SSMS显示select出来的数据行的疑问
  3. closest应用(向上查找最近的资料)
  4. poj 1099
  5. 探究linux文件
  6. 关于MPLS协议几个容易忽略的点
  7. Git详解之六 Git工具(转)
  8. Mac和Linux系统的:Arp欺骗源码
  9. JavaScript:int string 相互转化
  10. Select、Poll、Epoll、 异步IO 介绍
  11. 从零认识Java Package
  12. MVC设计模式的简单理解
  13. Kiwi Syslog安装笔记
  14. Spring MVC 数据绑定 (四)
  15. 流程控制:顺序结构: 代码默认从上到下依次执行 分支结构: 细分在分为如下 循环结构: while .. for ..
  16. php中的一些不常见的问题foreach/in_array[开发篇]
  17. npm cnpm +nodejs
  18. api管理平台
  19. BZOJ4313 : 三维积木
  20. iphone程序适配ipad可以用下面的宏进行尺寸改写

热门文章

  1. 参数依赖查找(ADL,Argument-dependent lookup)
  2. Android系统源代码——所需工具
  3. 具有SSM框架的CRUD与多条件查询
  4. Android--全局变量 很好很强大
  5. C# BackgroundWorker的Bug???
  6. html学习一(html简史及doctype)
  7. Spring mvc注解方式使用事务回滚
  8. Tomcat 文件夹结构
  9. atitit.thumb生成高质量缩略图 php .net c++ java
  10. atitit. java jsoup html table的读取解析 总结