exif_imagetype() 函数在linux下的php中不存在
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中不存在的更多相关文章
- [转载]linux下编译php中configure参数具体含义
编译N次了 原来这么回事 原文地址:linux下编译php中configure参数具体含义作者:捷心特 php编译参数的含义 ./configure –prefix=/usr/local/php ...
- linux下查找文件中空行的行号
linux下查找文件中空行的行号 linux下查找文件中空行的行号 以aa.txt举例: 方法1:sed -n '/[a-zA-Z0-9@#$%^&*]/!=' aa.txt 方法2:grep ...
- PHP在Linux下Apache环境中执行exec,system,passthru等服务器命令函数
更多内容推荐微信公众号,欢迎关注: 若在服务器中使用php test.php运行exec,system,passthru等命令相关的脚本能成功运行,在web页面却没反应, [可能是服务器端,PHP脚本 ...
- 【原创】Linux下编译链接中常见问题总结
前言 一直以来对Linux下编译链接产生的问题没有好好重视起来,出现问题就度娘一下,很多时候的确是在搜索帮助下解决了BUG,但由于对原因不求甚解,没有细细研究,结果总是在遇到在BUG时弄得手忙脚乱得. ...
- linux select函数:Linux下select函数的使用详解【转】
本文转载自;http://www.bkjia.com/article/28216.html Linux下select函数的使用 Linux下select函数的使用 一.Select 函数详细介绍 Se ...
- 用Go语言在Linux下调用新中新DKQ-A16D读卡器,读二代证数据
1.背景 前几天用Python在Linux下成功的获取了二代证数据,最近正在学Go语言,这两天想着用Go语言也实现一下试看看. 2.开搞C++ 这次就比较简单了,直接把CppDemo里面的SynRea ...
- 用Python在Linux下调用新中新DKQ-A16D读卡器,读二代证数据
1.背景 最近在研究二代证读卡器,手头上的设备是新中新DKQ-A16D,在官网(https://www.onecardok.com.cn/download)逛了一圈,发现Win下的示例,浏览器插件很多 ...
- Linux 下获取LAN中指定IP的网卡的MAC(物理地址)
// all.h// 2005/06/20,a.m. wenxy #ifndef _ALL_H#define _ALL_H #include <memory.h>#include < ...
- 如何在不使用系统函数的情况下实现PHP中数组系统函数的功能
PHP中为我们提供了各种各样的系统函数来实现我们需要的各种功能,那么,在不使用系统函数的情况下我们要怎样来实现这些功能呢?以下就是几种系统函数的实现方式. 首先,我们来定义一个数组: $arr= ar ...
随机推荐
- postgresql-slony-I同步复制配置步骤
主数据库: 172.16.254.21 端口:5432 从数据库: 172.16.254.22 端口:5432 步骤1:主从均安装slon apt-get install slon-bin 步骤2:主 ...
- [hdu 4959]Poor Akagi 数论(卢卡斯数,二次域运算,等比数列求和)
Poor Akagi Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- iOS开发-代码片段(Code Snippets)提高开发效率
简介 在 XCode4 引入了一个新特性,那就是“代码片段(Code Snippets)”.对于一些经常用到的代码,抽象成模板放到 Code Snippets 中,使用的时候就只需要键入快捷键就可以了 ...
- Android+手势识别详解
今天就来把以前的学习文章与经验简单总结中出来吧,在这里我就直接把代码贴下来了,希望能给初学者做最佳的学习参考,也希望有更多的开发人员来加入 ANDROID开发团队,参与更多的创新方式的开发,好了, ...
- UE初写小项目问题之命令行报错:Expected indentation of 4 spaces but found 6
一.问题 刚开始用一个小项目练手,用vue-cli初始化项目,直接安装了所有的东西,如vue-router.ESLint.unit tests等等,当时只懂得vue-router是什么. 问题来了,在 ...
- unity, 替换shader渲染(Rendering with Replaced Shaders)
实现特效,尤其是一些后处理特效,经常需要将各物体的shader替换为另一套shader进行渲染到纹理,再后再进行合成或以某种叠加方式叠加到最后的画面上去. 再复杂一点儿的,可能不同的物体所用的替换sh ...
- WCF实现RESTFul Web Service
共同学习了前面一些概念,终于开始正题了哈.RESTful的Web Service调用直观,返回的内容容易解析.这里先会描述一个简单的场景--Web Service提供一个方法来搜索个人信息,传入人名, ...
- HTML中css和js链接中的版本号
背景 在搜索引擎中搜索关键字.htaccess 缓存,你可以搜索到很多关于设置网站文件缓存的教程,通过设置可以将css.js等不太经常更新的文件缓存在浏览器端,这样访客每次访问你的网站的时候, 浏览器 ...
- sed n/N使用说明
sed的语法格式: sed [option] {sed-command} {input-file} sed在正常情况下,将处理的行读入模式空间(pattern space),脚本中的“sed-comm ...
- 我的高效编程的秘诀--开发环境的重要性(IOS)
我觉得一个好的开发环境,能够让一个开发者的工作效率提高两倍以上,也能够让一个小白看上去不那么蠢: 开发环境不是仅仅安装一个xcode这种ide就OK了,在我看来开发环境的部署范围比較广泛,以下我来说说 ...