If you find yourself in the unlikely scenario of not being able to use .htaccess to do something like this, you may find yourself in the even less likely scenario of needing this snippet.
Pass in a file path as a URL parameter or alter how $file is set to fit your needs and this snippet will ensure the image is downloaded as an attachment.
Note that to accomplish this same thing in supported HTML5 browsers, all you need to use is the HTML5 Download attribute.
// get the file file from a URL parameter (for example) $file = $_GET['fp']; $file = urldecode($file); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . 'myimage.png' . '"'); header('Content-Transfer-Encoding: binary'); header("Last-Modified: " . date( "D, j M Y H:i:s", strtotime("- 1 month"))); header("Expires: Thu, 20 Sep 2012 05:00:00 GMT"); header("Cache-Control: max-age=2692000, public"); header("Pragma: cache"); ob_clean(); flush(); readfile($file); exit;