PHP » I/O » file_exists()

Syntax:
bool file_exists(string filename)
filename
The name or path of the file to check for. On Windows, the double slash notation can be used to check for files on other computers.

Returns whether a file exists.

The file_exists() function can be used to check whether a specific file exists. It returns TRUE if the file exists and FALSE otherwise.

Examples

Code:
<?php

$file = "file_exists.php";

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

?>
Output:
The file file_exists.php exists
Explanation:

The code shows how to check the existence of a file.

See Also: