Changed mime detection to exif_imagetype to improve performance.