失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > exif_imagetype() 函数在linux下的php中不存在

exif_imagetype() 函数在linux下的php中不存在

时间:2018-12-05 08:26:31

相关推荐

exif_imagetype() 函数在linux下的php中不存在

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

}

如果觉得《exif_imagetype() 函数在linux下的php中不存在》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。