php determines whether the file exists or is readable or whether the directory exists. Combine three examples to ensure that you can understand it. Regarding php operating files, this aspect is both basic and very important. In many places, php is required to perform corresponding operations on files. , so you’d better take a good look at the following content
The code is as follows:
<?php $filename = './D243375_0.png'; $filename = realpath($filename); if (!file_exists($filename)) { die("图片不存在~!"); } $size = getimagesize ($filename); $file_extension = strtolower(substr(strrchr($filename,"."),1)); if("image/png" != $size['mime'] || $file_extension != "png"){ die("这不是一张完整的png图片"); } $img = @imagecreatefrompng ($filename); if($img){ ob_start("output_handler"); imagepng($img); ob_end_flush(); }else{ die("不能正确的创建png图形,请检查png图形是否完好~"); } function output_handler($img) { header('Content-type: image/png'); header('Content-Length:'.strlen($img)); return $img; } ?>
The above is the detailed content of PHP example code to detect whether png images are complete. For more information, please follow other related articles on the PHP Chinese website!