What are the potential pitfalls of using relative paths in PHP for file access?

Using relative paths in PHP for file access can lead to issues if the current working directory is not consistent or predictable. This can result in the wrong file being accessed or potential security vulnerabilities. To solve this, it is recommended to use absolute paths instead to ensure the correct file is always accessed regardless of the working directory.

$file = '/path/to/file.txt'; // Absolute path to the file
$data = file_get_contents($file);
echo $data;