Showing posts with label PHP exif_imagetype. Show all posts
Showing posts with label PHP exif_imagetype. Show all posts

Wednesday, 3 June 2015

PHP: Simple JPEG image validation

<?php
function validate_image(&$img)
{
 if ($img['type'] != 'image/jpeg') return false;
 if (@exif_imagetype($img['tmp_name']) != IMAGETYPE_JPEG) return false;
 return true;
}
?>
 

Usage

Pass as argument the $_FILES array for one image: $_FILES['img']