今天我通过以下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
收藏 打印