What function in PHP can be used to display a "Save As" option when clicking on files instead of opening images?

To display a "Save As" option when clicking on files instead of opening images in PHP, you can use the header() function to set the Content-Disposition to "attachment". This will prompt the browser to download the file instead of displaying it in the browser window.

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

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));

readfile($file);
exit;
?>