当前位置:Gxlcms > PHP教程 > php检测png图片是否完整的实例代码

php检测png图片是否完整的实例代码

时间:2021-07-01 10:21:17 帮助过:5人阅读

php判断文件是否存在或是否可读或目录是否存在结合三个实例保证你能看懂,关于php操作文件这方面即基础又很重要,在很多地方都需要php对文件进行相应的操作,所以你还是好好看看下面的内容

代码如下:

<?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; 
} 
?>

以上就是php 检测png图片是否完整的实例代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行