file_exists - Check if a file or directory exists
file_exists
(PHP 4, PHP 5)
file_exists - Check if a file or directory exists
Description
boolean file_exists (string $filename)
Check if the file or directory exists.
Parameters
File name
The path to the file or directory.
In Windows, use //computername/share/filename or computernameshare-filename to check for files on a network share.
Return value
Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
NOTE: This function will return FALSE for symlinks pointing to non-existent files.
Warning
This function returns FALSE for files that cannot enter safe mode due to restrictions. But these files can also be included if they are located in safe_mode_include_dir.
NOTE: The check is using real UID/GID which is not valid.
Example
Example #1 Test if file exists
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>