Call to undefined function exif_imagetype()

天大地大妈咪最大 提交于 2019-11-29 09:21:32

Enable the following extensions in php.ini and restart your server.

extension=php_mbstring.dll
extension=php_exif.dll

Then check phpinfo() to see if it is set to on/off

aesede

I think the problem is PHP config and/or version, for example, in my case:

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:

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
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 
    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";
}
?>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!