What are some potential pitfalls when using is_dir() to check for file existence in PHP?

Using is_dir() to check for file existence in PHP can be misleading because it specifically checks for directories, not files. To accurately check for file existence, it is better to use file_exists() instead. This will ensure that both files and directories are properly accounted for when checking for existence.

$file_path = 'path/to/file.txt';

if (file_exists($file_path)) {
    echo 'File exists!';
} else {
    echo 'File does not exist.';
}