How can headers be properly sent to enable downloading images with a link to the hard drive in PHP?

To enable downloading images with a link to the hard drive in PHP, you need to properly set the headers to indicate that the content being sent is an image file. This can be done by setting the Content-Type header to the appropriate image type (e.g., image/jpeg, image/png) and using readfile() function to output the image file.

<?php
$imagePath = '/path/to/image.jpg';

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

// Set headers for download
header('Content-Disposition: attachment; filename="' . basename($imagePath) . '"');

// Output the image file
readfile($imagePath);