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

PHP code used to determine whether the file exists, whether it is readable, and whether the directory exists

WBOY
Release: 2016-07-25 09:04:47
Original
937 people have browsed it
  1. $file = 'jbxue.com.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 = 'jbxue.com.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, otherwise returns FALSE.

Example 3:

  1. $file = 'jbxue.com.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.



source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template