What are the best practices for handling file paths and references in PHP to ensure proper display of images?

When handling file paths and references in PHP to ensure proper display of images, it is important to use the correct path format and ensure that the paths are relative to the location of the PHP file. It is also recommended to use the `__DIR__` magic constant to get the directory of the current file and construct the paths from there.

<?php
// Get the directory of the current file
$dir = __DIR__;

// Construct the path to the image file
$imagePath = $dir . '/images/image.jpg';

// Use the $imagePath in HTML to display the image
echo '<img src="' . $imagePath . '" alt="Image">';
?>