What could be the reason for an image not being displayed in PHP, even though the code appears to be correct?

The reason for an image not being displayed in PHP could be due to incorrect file path or permissions, improper image format, or errors in the code handling the image display. To solve this issue, check the file path and permissions, ensure the image format is supported, and verify that the code for displaying the image is correct.

<?php
$imagePath = 'path/to/your/image.jpg';

if (file_exists($imagePath)) {
    $imageInfo = getimagesize($imagePath);
    $imageType = $imageInfo['mime'];

    header('Content-Type: ' . $imageType);
    readfile($imagePath);
} else {
    echo 'Image not found.';
}
?>