How can the path to an image file be correctly specified in PHP code to ensure it is displayed properly in the output?

When specifying the path to an image file in PHP code, it is important to ensure that the path is correct relative to the location of the PHP file. One common mistake is not taking into account the file structure of the project, which can result in the image not being displayed properly. To solve this issue, you can use the `__DIR__` magic constant to get the directory of the current PHP file and then concatenate the image file path relative to that directory.

<?php
$image_path = __DIR__ . '/images/image.jpg';
echo '<img src="' . $image_path . '" alt="Image">';
?>