file_exists
(PHP 4, PHP 5, PHP 7, PHP 8)
Checks whether a file or directory exists
Description
Checks whether a file or directory exists.
Parameters
filenamePath to the file or directory.
On windows, use
//computername/share/filenameor\\computername\share\filenameto check files on network shares.
Return Values
Returns true if the file or directory specified by filename exists; false otherwise.
This function will return false for symlinks pointing to non-existing files.
The check is done using the real UID/GID instead of the effective one.
32bit
Errors/Exceptions Failure
Examples
Testing whether a file exists
<?php
$filename = '/path/to/foo.txt';
if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>Notes Clearstatcache Stat
See Also
is_readable()is_writable()is_file()file()SplFileInfo