PHP file_exists() Function
In this chapter you will learn:
- Definition for PHP file_exists() Function
- Syntax for PHP file_exists() Function
- Parameter for
- Return for PHP file_exists() Function
- Example - Check if a file exists
Definition
The file_exists() function checks whether or not a file or directory exists.
Syntax
PHP file_exists() Function has the following syntax.
file_exists(path)
Parameter
Parameter | Is Required | Description |
---|---|---|
path | Required. | Path to check |
Return
Returns TRUE if the file or directory specified by filename exists; FALSE otherwise.
Example
file_exists() returns true if the file exists and false otherwise.
We can use file_exists() to discover whether a file exists before attempting to open it:
<?PHP//from j ava 2 s. c o m
if (file_exists("data.txt")) {
print "data.txt exists!\n";
} else {
print "data.txt does not exist!\n";
}
echo file_exists("data.txt");
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Definition for PHP file_get_contents() Function
- Syntax for PHP file_get_contents() Function
- Parameter for PHP file_get_contents() Function
- Return for PHP file_get_contents() Function
- Note for PHP file_get_contents() Function
- Example - Read text file
Home » PHP Tutorial » PHP File Functions