Forum Moderators: coopster
$c = qnr("select * from ".$pre."download where userid = ".$userid." and active = 0 and filehash = ".$_GET['id']);
if (!$c)
die("You do not have access to download this file.");
$tic = qr("select * from ".$pre."admin");
if ($c['times'] >= $tic['maxdownload'])
die("You have already downloaded this file ".$c['times']." times and are not allowed to download it again.");
q("update ".$pre."download set times = times + 1 where filehash = ".$_GET['id']." and active = 0 and userid = ".$userid);
$file = "mp3/".$r['filename'];
$fp=fopen($file,"rb");
if ($fp) {
$file = $r['filename'];
$filesize = filesize($file);
ob_end_clean();
// Create the headers used for downloading the file
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg");
header("Content-Length: " . $filesize);
header("Content-Disposition: attachment; filename= " . str_replace(" ","_",$file) . ";");
// Actually start downloading the file
while (!feof($fp)) {
echo(fgets($fp, 4096));
}
fclose ($fp);
} else {
die("Some kinda error.");
}
?>