且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JPG,JPEG,PNG的文件类型检查

更新时间:2023-11-25 17:35:16

您应该打开文件并查看其中的内容,而不是尝试通过扩展名检测文件类型.

Instead of try to detect the file type by extension, you should open the file and see what's in it.

$allowed_types = array(IMAGETYPE_GIF,IMAGETYPE_JPEG,IMAGETYPE_PNG);
if (in_array(exif_imagetype($_FILES["upload_picture"]["tmp_name"]), $allowed_types)){
    //is either jpeg, png or gif
}

http://php.net/manual/en/function.exif- imagetype.php