2

I have the following code for creating thumbnails of the images in the database automatically when the are uploaded.

<?php
include('config.php');
$result = mysql_query("SELECT * FROM photos where caption='cars'");
while($row = mysql_fetch_array($result))
{
    echo '<div id="imagelist">';
    echo '<p><img src="'.$row['location'].'"></p>';
    echo '</div>';
}
?>

Now whenever I click an image in the gallery I want it to open the image in a new tab and give me an option to download, I want the download code which will take in the photo id from the database and then give me the option to download that image only how to do it.

4

1 回答 1

2

Try this :

    $file    = your 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);
    exit;

mysql_* functions are deprecated in new version of php, So use mysqli_* functions OR PDO

于 2013-03-28T06:33:09.307 回答