Home >Backend Development >PHP Tutorial >PHP uses file_exists to check if a file or directory exists

PHP uses file_exists to check if a file or directory exists

WBOY
WBOYOriginal
2016-07-25 09:04:501033browse
  1. $filename = '/jbxue.com/aa/to/foo.txt';
  2. if (file_exists($filename)) {
  3. echo "File $filename exists";
  4. } else {
  5. echo "File $filename does not exist";
  6. }
  7. ?>
Copy code

Output result: The file /jbxue.com/aa/to/foo.txt already exists

Example 2:

  1. echo file_exists("jbxue.com.txt");
  2. ?>
Copy code

Directly use file_exists to return true or false



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