定义

file_exists()函数检查文件或目录是否存在。

 

语法

PHP file_exists()函数具有以下语法。

file_exists(path)

 

参数

参数 是否必须 描述
path 需要。 检查路径

 

返回值

如果filename指定的文件或目录存在,则返回TRUE; 否则为FALSE。

 

实例

file_exists()如果文件存在则返回true,否则返回false。

在尝试打开文件之前,我们可以使用file_exists()来发现文件是否存在:

<?php
/*
http://www.manongjc.com/article/1790.html
作者:码农教程
*/
      if (file_exists(\"data.txt\")) {
         print \"data.txt exists!\\n\";
      } else {
         print \"data.txt does not exist!\\n\";
      }


      echo file_exists(\"data.txt\");

?>

上面的代码生成以下结果:

data.txt does not exist!

收藏 打印