How can the header() function be used to ensure proper display of images in PHP?

When displaying images in PHP, it is important to set the correct content type in the HTTP response headers using the header() function. This ensures that the browser interprets the response as an image file and displays it correctly. By setting the content type to "image/jpeg", "image/png", or "image/gif" before outputting the image data, you can ensure proper display of images in PHP.

<?php
// Set the content type header to indicate that the response is an image
header('Content-Type: image/jpeg');

// Output the image data
echo file_get_contents('path/to/image.jpg');