What are the potential pitfalls of using file_exists() in PHP?

The potential pitfall of using file_exists() in PHP is that it can return true for directories as well as files, which may not be the intended behavior. To solve this issue, you can use is_file() instead to specifically check if a path is a regular file.

// Check if a path is a regular file
if (is_file($path)) {
    // File exists and is a regular file
    echo "File exists and is a regular file.";
} else {
    // File does not exist or is not a regular file
    echo "File does not exist or is not a regular file.";
}