How can the __DIR__ constant be used to improve file path handling in PHP?

When working with file paths in PHP, it's important to ensure that paths are correctly resolved regardless of the current working directory. One way to improve file path handling is by using the `__DIR__` constant, which represents the directory of the current PHP script. By using `__DIR__`, you can create absolute paths that are not affected by changes in the working directory.

// Using __DIR__ to create an absolute path
$filePath = __DIR__ . '/data/file.txt';

// Opening a file using the absolute path
$file = fopen($filePath, 'r');

// Reading the contents of the file
echo fread($file, filesize($filePath));

// Closing the file
fclose($file);