php判断文件是否存在
php判断文件是否存在其实很简单,只需要一个函数即可:file_exists(文件路径);
用此函数一般用来判断文件是否存在,然后操作,常用的有删除文件:unlink(文件路径);
用此函数一般用来判断文件是否存在,然后操作,常用的有删除文件:unlink(文件路径);
代码如下 | 复制代码 |
if(file_exists("data.txt")) { print("这个文件存在"); //文件存在 print(fileinode("data.txt")); } else { print("文件不存在"); //文件不存在 } |
方法二
代码如下 | 复制代码 |
<?php session_start(); if($submit=="查找"){ $file_up=$_post[files]; if(file_exists($file_up)){ echo "文件已经存在!!"; }else{echo "该文件不存在!!";} } ?> |
方法三
代码如下 | 复制代码 |
<?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; } ?> |
文章地址:http://www.phprm.com/develop/34967.html
转载随意^^请带上本文地址!