php Call to undefined function exif_imagetype()解决方法

时间:2016-08-30
今天使用php的exif_imagetype函数出了一点小问题,抛出错误Call to undefined function exif_imagetype(),后来网上查阅了以下资料才解决掉,现在和大家分享一下解决方法。

今天我通过以下php代码获取图片文件的Mime-Type:

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
        /*  http://www.manongjc.com/article/1416.html */

    }

}

运行代码时,抛出错误Call to undefined function exif_imagetype()。 原因是我们没有在php.ini中开启扩展,具体做法如下:

在php.ini中搜索extension=php_mbstring.dll,然后将前面的分号去掉,即:

extension=php_mbstring.dll
extension=php_exif.dll