How can the use of relative paths in PHP scripts lead to errors or issues with file access permissions?

When using relative paths in PHP scripts, the script's working directory can vary depending on how the script is executed. This can lead to file access permission errors if the script tries to access files outside of its expected directory. To solve this issue, it's recommended to use absolute paths instead of relative paths to ensure that the script always accesses the correct files regardless of the working directory.

// Using absolute path to access a file
$file = '/var/www/html/data/file.txt';

if (file_exists($file)) {
    $content = file_get_contents($file);
    echo $content;
} else {
    echo 'File not found';
}