Использовать FILEINFO_MIME_TYPE
$filename = 'example.jpeg';
// Get file info
$finfo = new finfo();
$fileinfo = $finfo->file($filename); // return JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, progressive, precision 8, 875x350, frames 3
$info = $finfo->file($filename, FILEINFO_MIME); // return 'image/jpeg; charset=binary'
$type = $finfo->file($filename, FILEINFO_MIME_TYPE); // return 'image/jpeg'
switch($type)
{
case 'image/jpg':
case 'image/jpeg':
// code...
break;
case 'image/gif':
// code...
break;
case 'image/png':
// code...
default:
// error...
break;
}