How can PHP scripts be modified to properly output image content for Fancybox display?

To properly output image content for Fancybox display, PHP scripts can be modified to send the correct headers and output the image data. This can be achieved by reading the image file, setting the appropriate content-type header, and then outputting the image data.

<?php
// Path to the image file
$image_path = 'path/to/your/image.jpg';

// Get the image file extension
$image_extension = pathinfo($image_path, PATHINFO_EXTENSION);

// Set the appropriate content-type header
header('Content-Type: image/' . $image_extension);

// Output the image data
readfile($image_path);