Here's the script I use to download files from a database:
PHP Code:
<?php
session_start();
$userAccess = $_SESSION['level'];
if(isset($_GET['id']))
{
//download file
include ('dbconnect.php');
$id = $_GET['id'];
$query = "SELECT name, type, size, content FROM upload WHERE id='$id' AND access<='$userAccess'";
$result = mysql_query($query) or die(mysql_error());
list($name, $type, $size, $content) = mysql_fetch_array($result);
header('Cache-Control: maxage=3600');
header('Pragma: public');
header("Content-length: $size");
header("Content-type: $type");
header('Content-Disposition: attachment; filename="'.$name.'"');
echo $content;
mysql_close($db);
exit;
}
?>
And the link to download the file looks like this:
HTML Code:
<a href="download.php?id=37">Download</a>
Bookmarks