What potential issues can arise when displaying data from a file in PHP, as seen in the provided code snippet?

One potential issue that can arise when displaying data from a file in PHP is the lack of proper error handling. If the file does not exist or cannot be read, it can result in errors or unexpected behavior. To solve this issue, it is important to check if the file exists and is readable before attempting to display its contents.

<?php
$filename = 'data.txt';

if (file_exists($filename) && is_readable($filename)) {
    $data = file_get_contents($filename);
    echo $data;
} else {
    echo "Error: Unable to read file.";
}
?>