What are common mistakes made when trying to display images using PHP?

Common mistakes when displaying images using PHP include not setting the correct content type header, not specifying the correct image path, and not handling errors properly. To solve these issues, make sure to set the content type header to the appropriate image type (e.g. image/jpeg, image/png), provide the correct image path, and use error handling to display any errors that may occur.

<?php
// Set the content type header
header('Content-Type: image/jpeg');

// Specify the correct image path
$imagePath = 'path/to/image.jpg';

// Display the image
if(file_exists($imagePath)){
    readfile($imagePath);
} else {
    echo 'Image not found';
}
?>