Home >Backend Development >PHP Tutorial >file_exists() function in PHP
The file_exists method checks whether a file or directory exists. It accepts as argument the path of the file or directory to be checked. Here's what it's used for -
It's useful when you need to know if a file exists before processing it.
In this way, when creating a new file, use this function to know whether the file already exists.
file_exists($file_path)
##file_path - Set the file or directory to check whether it exists path of. Required.
<?php $myfile = '/doc/candidate.txt'; if (file_exists($myfile)) { echo "$myfile exists!"; } else { echo "$myfile does not exist!"; } ?>The following is the output showing that the file does not exist. Output
/doc/candidate.txt does not exist!
The above is the detailed content of file_exists() function in PHP. For more information, please follow other related articles on the PHP Chinese website!