PHP判断本地文件是否存在可以使用is_file()、file_exists()函数。
is_file()函数方法
is_file 判断文件是否存在并且检查指定的文件名是否是正常的文件;
<?php
header("Content-type:text/html;charset=utf-8");
$file = "check.txt";
if(is_file($file))
{
echo "当前目录中,文件".$file."存在";
}
else
{
echo "当前目录中,文件".$file."不存在";
}
?>file_exists()函数方法
file_exists 判断文件是否存在或者是目录是否存在;
<?php
header("Content-type:text/html;charset=utf-8");
$file = "test.txt";
if(file_exists($file))
{
echo "当前目录中,文件".$file."存在";
}
else
{
echo "当前目录中,文件".$file."不存在";
}
?
