利用getimagesize函数:
function isImage($filename){
$types = '.gif|.jpeg|.png|.bmp';//定义检查的图片类型
if(file_exists($filename)){
$info = getimagesize($filename);
$ext = image_type_to_extension($info['2']);
return stripos($types,$ext);
}else{
return false;
}
}
if(isImage('test.jpg')!==false){
echo '是图片';
}else{
echo '不是';
}
转载于:https://www.cnblogs.com/shaohuixia/p/5464687.html