使用php判断文件是否存在、是否可读、目录是否存在

php教程评论660 views阅读模式
  1. $file = 'bbs.it-home.org.php';
  2. if (is_readable($file) == false) {
  3. die('文件不存在或者无法读取');
  4. } else {
  5. echo '存在';
  6. }
  7. ?>

复制代码

is_readable() 函数判断指定文件名是否可读。 指定的文件或目录存在并且可读,则返回 TRUE

例2:

  1. $filename = 'bbs.it-home.org.php';
  2. if (file_exists($filename)) {
  3. echo "The file $filename exists";

复制代码

file_exists -- 检查文件或目录是否存在 说明 bool file_exists ( string filename ) 如果由 filename 指定的文件或目录存在则返回 TRUE,否则返回 FALSE。

例3:

复制代码

is_file -- 判断给定文件名是否为一个正常的文件 说明 bool is_file ( string filename) 如果文件存在且为正常的文件则返回 TRUE。

企鹅博客
  • 本文由 发表于 2019年9月7日 00:12:55
  • 转载请务必保留本文链接:https://www.qieseo.com/318515.html

发表评论