views:

20

answers:

1
+1  Q: 

Page content type

I have a list of links for the page which point to the images. When I click some the image opens in the browser, and I need to make it downloadable (use have to see the window for image saving). As I udnerstand, I have to make script (php only), and use it in that links addresses, passing the image name to it. Then, somehow change the content type page and ask user to download file. Can you help me with this script?

+1  A: 

From PHP.net

<?php
$file = 'monkey.gif';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
}
?>
konforce