submitted by:

PHP: check if a file or directory exists

To determine whether a file exists on the server, PHP has a simple function: file_exists(). This can also be used to determine if a directory exists.


code snippet:
<?php

$filename 
'/optional/path/file.txt';

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

?>