PHP file_exists: Usage & Examples

The file_exists function is used to determine if a file or directory exists. Its syntax is as follows:

bool file_exists ( string $filename )

The parameter $filename is the path of the file or directory to be checked. It will return true if the file or directory exists, otherwise it will return false. Here is an example:

if (file_exists("myfile.txt")) {
    echo "文件存在";
} else {
    echo "文件不存在";
}
bannerAds