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']);
        }

exif_imagetype() 函数在linux下的php中不存在的更多相关文章

  1. [转载]linux下编译php中configure参数具体含义

    编译N次了   原来这么回事 原文地址:linux下编译php中configure参数具体含义作者:捷心特 php编译参数的含义 ./configure –prefix=/usr/local/php ...

  2. linux下查找文件中空行的行号

    linux下查找文件中空行的行号 linux下查找文件中空行的行号 以aa.txt举例: 方法1:sed -n '/[a-zA-Z0-9@#$%^&*]/!=' aa.txt 方法2:grep ...

  3. PHP在Linux下Apache环境中执行exec,system,passthru等服务器命令函数

    更多内容推荐微信公众号,欢迎关注: 若在服务器中使用php test.php运行exec,system,passthru等命令相关的脚本能成功运行,在web页面却没反应, [可能是服务器端,PHP脚本 ...

  4. 【原创】Linux下编译链接中常见问题总结

    前言 一直以来对Linux下编译链接产生的问题没有好好重视起来,出现问题就度娘一下,很多时候的确是在搜索帮助下解决了BUG,但由于对原因不求甚解,没有细细研究,结果总是在遇到在BUG时弄得手忙脚乱得. ...

  5. linux select函数:Linux下select函数的使用详解【转】

    本文转载自;http://www.bkjia.com/article/28216.html Linux下select函数的使用 Linux下select函数的使用 一.Select 函数详细介绍 Se ...

  6. 用Go语言在Linux下调用新中新DKQ-A16D读卡器,读二代证数据

    1.背景 前几天用Python在Linux下成功的获取了二代证数据,最近正在学Go语言,这两天想着用Go语言也实现一下试看看. 2.开搞C++ 这次就比较简单了,直接把CppDemo里面的SynRea ...

  7. 用Python在Linux下调用新中新DKQ-A16D读卡器,读二代证数据

    1.背景 最近在研究二代证读卡器,手头上的设备是新中新DKQ-A16D,在官网(https://www.onecardok.com.cn/download)逛了一圈,发现Win下的示例,浏览器插件很多 ...

  8. Linux 下获取LAN中指定IP的网卡的MAC(物理地址)

    // all.h// 2005/06/20,a.m. wenxy #ifndef _ALL_H#define _ALL_H #include <memory.h>#include < ...

  9. 如何在不使用系统函数的情况下实现PHP中数组系统函数的功能

    PHP中为我们提供了各种各样的系统函数来实现我们需要的各种功能,那么,在不使用系统函数的情况下我们要怎样来实现这些功能呢?以下就是几种系统函数的实现方式. 首先,我们来定义一个数组: $arr= ar ...

随机推荐

  1. 加速nginx: 开启gzip

    nginx 是一个高性能的 Web 服务器,之前也写过一些关于 nginx 的文章.为了提高博客的响应速度,可以从设置 nginx 的 gzip 和缓存这2方面入手.为字体开启 gzip 和缓存能大大 ...

  2. 使用rman备份异机恢复数据库

    一.RMAN备份源库注意点: 最好保留rman备份日志 $rman target / log=backup.log RMAN>run { allocate channel t1 type dis ...

  3. 摘:数据结构各种算法实现(C++模板)

    目  录 1.顺序表. 1 Seqlist.h 1 Test.cpp 6 2.单链表. 8 ListNode.h 8 SingleList.h 10 test.cpp 20 3.双向链表. 22 No ...

  4. Zepto源代码分析一~核心方法

    今天抽出时间复习了一下Zepto的源代码,依照自己的理解进行凝视. 欢迎大家拍砖. 源代码版本号:v1.1.4 源代码下载地址:http://zeptojs.com/ 分析总体代码之后,整理出架构图: ...

  5. AESDK从流中获得变换信息

    AE中Transform下的信息位于流中,和别的软件不太一样. 如果是特效的参数信息要从EffectSuites中获取,默认的参数信息基本上StreamSuites都可以得到 需要注意,取得流之后也要 ...

  6. 通过CLR API实现C++调用C#代码交互

    对于某些跨平台程序,这也就意味着只能在windows下使用了 不过最近.Net开源或许以后可以跨平台 之前花了一些时间研究COM方式调用,太繁琐不推荐. COM方式调用总结 后来尝试使用CLR C++ ...

  7. java工程资源文件夹嵌套建立!

    做过一遍忘了,找了半天!记这里,看你还忘不忘!

  8. ENGINE_API CXSroll

    #ifndef __XSROLL_H__ #define __XSROLL_H__ #include "CocoHead.h" #include "XWindow.h&q ...

  9. 使用libjpeg 压缩yuv420到jpg (内存方式)

    #include <Windows.h> #include <stdio.h> extern "C" { #include <jpeglib.h> ...

  10. ORACLE用户角色与授权

    --创建一个用户CREATE USER test_user IDENTIFIED BY test_user; --创建一个角色 CREATE ROLE connect2 ; --为角色授权 GRANT ...