Call to undefined function exif_imagetype()

穿精又带淫゛_ 提交于 2019-11-30 08:55:35

问题


I am trying to get Mime-Type for image-types as follow:

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?


回答1:


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




回答2:


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



回答3:


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";
}
?>


来源:https://stackoverflow.com/questions/16175702/call-to-undefined-function-exif-imagetype

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