How can one ensure that relative path references in PHP fopen functions are correctly pointing to the desired file location within the directory structure?

When using relative path references in PHP fopen functions, it's important to ensure that the paths are correct based on the current working directory. To do this, you can use the `__DIR__` magic constant to get the absolute path of the current script and then concatenate the relative path to it. This way, you can be sure that the fopen function will correctly point to the desired file location within the directory structure.

$filePath = __DIR__ . '/relative/path/to/file.txt';
$file = fopen($filePath, 'r');
// Rest of the code to read or write to the file
fclose($file);