What are the potential pitfalls of using the header function in PHP for image display?

Using the header function in PHP for image display can lead to potential pitfalls such as browser caching issues and incorrect content-type headers being set. To solve this, it is recommended to use readfile() function to output the image content directly to the browser.

<?php
$image_path = 'path_to_your_image.jpg';

header('Content-Type: image/jpeg');
readfile($image_path);
exit;
?>