What are the best practices for handling relative paths in PHP scripts to avoid errors like "stream does not support seeking"?
When working with relative paths in PHP scripts, it is important to use the `__DIR__` magic constant to get the absolute path of the current file. This helps avoid errors like "stream does not support seeking" when trying to open files using relative paths. By using `__DIR__` to construct the full path to the file, you ensure that the file is accessed correctly regardless of the current working directory.
// Construct the absolute path using __DIR__
$file = __DIR__ . '/relative/path/to/file.txt';
// Open the file using the absolute path
$handle = fopen($file, 'r');
// Read from the file
$data = fread($handle, filesize($file));
// Close the file
fclose($handle);