Home >Backend Development >PHP Tutorial >Use php to determine whether the file exists, whether it is readable, and whether the directory exists

Use php to determine whether the file exists, whether it is readable, and whether the directory exists

WBOY
WBOYOriginal
2016-07-25 09:03:321174browse
  1. $file = 'bbs.it-home.org.php';
  2. if (is_readable($file) == false) {
  3. die('The file does not exist or cannot be read' );
  4. } else {
  5. echo 'exists';
  6. }
  7. ?>
Copy code

is_readable() function determines whether the specified file name is readable. Returns TRUE if the specified file or directory exists and is readable

Example 2:

  1. $filename = 'bbs.it-home.org.php';
  2. if (file_exists($filename)) {
  3. echo "The file $filename exists";
  4. } else {
  5. echo "The file $filename does not exist";
  6. }
  7. ?>
Copy code

file_exists -- Check whether the file or directory exists illustrate bool file_exists (string filename) Returns TRUE if the file or directory specified by filename exists, FALSE otherwise.

Example 3:

  1. $file = 'bbs.it-home.org.php';
  2. if (is_file($file) == false) {
  3. die('The file does not exist or cannot be read ');
  4. } else {
  5. echo 'exists';
  6. }
  7. ?>
Copy code

is_file -- Determine whether the given file name is a normal file illustrate bool is_file (string filename) Returns TRUE if the file exists and is a normal file.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn