What are potential pitfalls when using file_get_contents to check for file existence in PHP?

When using file_get_contents to check for file existence in PHP, a potential pitfall is that it will return false not only if the file does not exist, but also if the file is not readable. To avoid this issue, you can use the file_exists function to specifically check for file existence before attempting to read the file with file_get_contents.

$file_path = 'example.txt';

if (file_exists($file_path)) {
    $file_contents = file_get_contents($file_path);
    // Do something with the file contents
} else {
    echo 'File does not exist.';
}