php 调用未定义的函数 exif_imagetype()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16175702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call to undefined function exif_imagetype()
提问by Subedi Kishor
I am trying to get Mime-Type
for image-types
as follow:
我试图让Mime-Type
为image-types
如下:
if(!empty($_FILES['uploadfile']['name']) && $_FILES['uploadfile']['error'] == 0){
$file = $_FILES['uploadfile']['tmp_name'];
$file_type = image_type_to_mime_type(exif_imagetype($file));
switch($file_type){
// Codes Here
}
}
But it always gives the error Call to undefined function exif_imagetype()
. What am I doing wrong here?
但它总是给出错误Call to undefined function exif_imagetype()
。我在这里做错了什么?
回答by samayo
Enable the following extensions in php.ini
and restart your server.
启用以下扩展php.ini
并重新启动服务器。
extension=php_mbstring.dll
extension=php_exif.dll
扩展名=php_mbstring.dll
扩展名=php_exif.dll
Then check phpinfo()
to see if it is set to on/off
然后检查phpinfo()
它是否设置为开/关
回答by aesede
I think the problem is PHP config and/or version, for example, in my case:
我认为问题在于 PHP 配置和/或版本,例如,就我而言:
We know exif_imagetype()
takes a file path or resource and returns a constant like IMAGETYPE_GIF
and image_type_to_mime_type()
takes that constant value and returns a string 'image/gif'
, 'image/jpeg'
, etc.
This didn't work (missing function exif_imagetype), so I've found that image_type_to_mime_type()
can also take an integer 1, 2, 3, 17, etc. as input,
so solved the problem using getimagesize, which returns an integer value as mime type:
我们知道exif_imagetype()
需要一个文件路径或资源,并返回像IMAGETYPE_GIF一个常数,image_type_to_mime_type()
采用的是恒定值,并返回一个字符串'image/gif'
,'image/jpeg'
等等。这并没有工作(缺少功能exif_imagetype),所以我发现, image_type_to_mime_type()
还可以采取整数1 , 2, 3, 17 等作为输入,所以使用 getimagesize 解决了这个问题,它返回一个整数值作为 mime 类型:
function get_image_type ( $filename ) {
$img = getimagesize( $filename );
if ( !empty( $img[2] ) )
return image_type_to_mime_type( $img[2] );
return false;
}
echo get_image_type( 'my_ugly_file.bmp' );
// returns image/x-ms-bmp
echo get_image_type( 'path/pics/boobs.jpg' );
// returns image/jpeg
回答by Imane Fateh
Add this to your code so as we could know which version of php you do have because this function is only supported by (PHP version 4 >= 4.3.0, PHP 5).
将此添加到您的代码中,以便我们知道您使用的是哪个版本的 php,因为此功能仅受 (PHP version 4 >= 4.3.0, PHP 5) 支持。
<?php
phpinfo();
?>
It may be not installed, you can add this part of code to make sure it is :
它可能没有安装,您可以添加这部分代码以确保它是:
<?php
if (function_exists('exif_imagetype')) {
echo "This function is installed";
} else {
echo "It is not";
}
?>