What potential pitfalls should be avoided when using file_exists() in PHP, as seen in the provided code snippet?
When using file_exists() in PHP, it is important to remember that the function can return true for directories as well as files. This can lead to unexpected behavior if you are specifically checking for files. To avoid this pitfall, you can use is_file() instead of file_exists() to specifically check if a path is a regular file.
// Check if a file exists and is a regular file
$filePath = 'path/to/file.txt';
if (file_exists($filePath) && is_file($filePath)) {
echo 'The file exists and is a regular file.';
} else {
echo 'The file does not exist or is not a regular file.';
}