Check if Image Exists or Not corrupted in Php

Check if Image Exists or Not corrupted in Php

stackofcodes.in

$full_path = Full Image path; (Like: ../dd/tmp.jpg)

if(!file_exists($full_path)){

//Image Not Available or Not Exists

}else{
//Image File Exists

//Check if image not damaged.
$ext = strtolower(pathinfo($full_path, PATHINFO_EXTENSION));
if ($ext === ‘jpg’) { $ext = ‘jpeg’; }
$function = ‘imagecreatefrom’ . $ext;

if (function_exists($function) && @$function($full_path) === FALSE)
{
//Image Is Corrupted or Damaged.
}else{
// Image is Ok
}

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *