PHP file_exists: How to Check if a File Exists

In PHP, you can use the file_exists() function to check if a file exists. For example:

$file = "example.txt";

if(file_exists($file)){
    echo "文件存在。";
} else {
    echo "文件不存在。";
}

In the example above, the file name “example.txt” is first defined to be checked, then the file existence is verified using the function “file_exists()”, and a corresponding message is output based on the return value.

bannerAds