调用未定义功能exif_imagetype()(Call to undefined function

2019-08-31 23:10发布

我试图让Mime-Typeimage-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

    }

}

但它总是给错误Call to undefined function exif_imagetype() 我在做什么错在这里?

Answer 1:

启用以下扩展名php.ini并重新启动服务器。

延长=中php_mbstring.dll
延长= php_exif.dll

然后检查phpinfo() ,看它是否被设置为开/关



Answer 2:

我认为这个问题是PHP配置和/或版本,例如,在我的情况:

我们知道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


Answer 3:

添加到您的代码,以便我们可以知道你有哪些PHP的版本,因为该功能只能通过(PHP版本4> = 4.3.0,PHP 5)支持。

<?php 
    phpinfo(); 
?> 

它可能没有安装,你可以添加这部分代码,以确保它是:

<?php
if (function_exists('exif_imagetype')) {
    echo "This function is installed";
} else {
    echo "It is not";
}
?>


文章来源: Call to undefined function exif_imagetype()