Home > Backend Development > PHP Tutorial > PHP detects whether png images are intact_PHP tutorial

PHP detects whether png images are intact_PHP tutorial

WBOY
Release: 2016-07-21 14:54:13
Original
1005 people have browsed it

php checks whether the png image is intact


$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("Cannot create png graphics correctly, please Check whether the png graphics are intact~");
}

function output_handler($img) {
header('Content-type: image/png');
header('Content- Length:'.strlen($img));
return $img;
}
?>

This article address: http://www.52blogger.com/archives/574 Please keep it for reprinting

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364632.htmlTechArticlephp checks whether the png image is intact?php $filename = ./D243375_0.png; $filename = realpath($filename ); if (!file_exists($filename)) { die(image does not exist~!); } $size = getimagesize ($fi...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template