March 3, 2012
Check image type if renamed from .png to .jpg
Question by John
If it possible to check if the type of image if it was renamed from .png
to .jpg
?
I need this because when I use a resize function my website stop working if the uploaded image was renamed from .png to .jpg (I made my code to accept only .jpg images)
Answer by dev-null-dweller
getimagesize will contain info about image type:
$info = getimagesize('file.png');
if($info[2] == IMAGETYPE_JPEG){
}
Answer by Starx
You can always read the image type to check an image using exif_imagetype()
$image_type = exif_imagetype($filename);
Example:
<?php
if (exif_imagetype('image.gif') != IMAGETYPE_GIF) {
echo 'The picture is not a gif';
}
?>