Copy code The code is as follows:
$filename = './D243375_0.png';
$filename = realpath($filename);
if (!file_exists($filename)) {
die("The picture does not exist~!");
}
$size = getimagesize ($filename);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if(" image/png" != $size['mime'] || $file_extension != "png"){
die("This is not a complete png picture");
}
$img = @imagecreatefrompng ($filename );
if($img){
ob_start("output_handler");
imagepng($img);
ob_end_flush();
}else{
die("The png graphic cannot be created correctly, please check whether the png graphic is intact ~");
}
function output_handler($img) {
header('Content-type: image/png');
header('Content-Length:'.strlen($img));
return $img;
}
?>
The above introduces the PHP code to detect whether the png image is complete, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.