• PHP Video Tutorials

PHP - Function file_exists()



The file_exists() function can check whether or not a file or directory exists. This function returns true if the file or directory exists, otherwise returns false.

Syntax

bool file_exists ( string $filename )

This function can check whether a file or directory exists.

Example

<?php
   $filename = "/PhpProject/sample.txt";

   if(file_exists($filename)) {
      echo "The file $filename exists";
   } else {
      echo "The file $filenamedoes not exist";
   }
?>

Output

The file /PhpProject/sample.txt exists
php_function_reference.htm
Advertisements