I'm creating a script to upload image file. There are two ways to verify if the file is an image.
First one is by checking the extension:
$extension = strtolower(substr($filename, strrpos($filename, '.') + 1, strlen($filename) - strrpos($filename, '.')));
if ($extension == "jpg") // UPLOAD
Another one is by checking the mime type:
$imageinfo = getimagesize($filename);
if ($imageinfo['mime'] == "image/jpeg") // UPLOAD
Which one is the better method to verify if the file is an image?