php如何查询文件是否存在

  • 时间:
  • 来源:网络

   

php查询文件是否存在的方法:使用自带的函数【file_exists】判断文件是否存在,代码为【if(file_exists($file)){echo "当前目录中,文件".$file."存在"}】。

php查询文件是否存在的方法:

判断文件或目录是否存在有自带的函数

file_exists:文件是否存在

$file = "check.txt";
if(file_exists($file))
{
    echo "当前目录中,文件".$file."存在";
}
else
{
     echo "当前目录中,文件".$file."不存在";
}

is_dir:目录是否存在

$dir = "c:/datacheck";
if(is_dir($dir))
{
    echo "当前目录下,目录".$dir."存在";
}
else
{
     echo "当前目录下,目录".$dir."不存在";
}

相关学习推荐:php编程(视频)