What are some potential pitfalls when trying to output images in PHP using the header() function?
One potential pitfall when using the header() function to output images in PHP is not setting the correct content type. This can result in the image not being displayed correctly or not at all. To solve this issue, you need to set the content type to 'image/jpeg', 'image/png', or 'image/gif' depending on the image type you are outputting.
<?php
// Set the content type header based on the image type
header('Content-Type: image/jpeg');
// Output the image file
readfile('path/to/image.jpg');
?>