What are some best practices for debugging PHP scripts that are not displaying images correctly?

When PHP scripts are not displaying images correctly, one common issue could be incorrect file paths or permissions. To debug this issue, check the file paths in your code and ensure they are correct. Additionally, check the file permissions to make sure the web server has access to the image files.

<?php
$imagePath = 'images/image.jpg';

// Check if the image file exists
if (file_exists($imagePath)) {
    // Display the image
    echo '<img src="' . $imagePath . '" alt="Image">';
} else {
    echo 'Image not found.';
}
?>