Forum Moderators: coopster

Message Too Old, No Replies

script help

         

FiRe

12:04 am on May 14, 2006 (gmt 0)

10+ Year Member



Hey guys, my mate has this script that allows u to download mp3 files once u paid. However if u click on the download link a second time without refreshing the page u just got the mp3 files code not a download box. This problem seems to be in IE only and I cant figure out why. Can any1 spot the error?
----------------
<?php
require 'config.php';
require 'db.php';
$a = qnr("select * from ".$pre."users where hash LIKE '".$_GET['s']."'");
if (!$a) {
die("Sorry, I don't know who you are.");
}
$userid = $a['id'];
$r = qnr("select * from ".$pre."filehash where fileid = ".$_GET['id']);
if (!$r)
die("File does not exist. Please contact the administrator.");

$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.");
}
?>

Habtom

5:18 am on May 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you think it has got to do with cleaning the buffer?

//ob_end_clean();

Habtom

dreamcatcher

7:01 am on May 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or try adding exit. I know someone who had a similar problem and this solved it for him.

echo(fgets($fp, 4096));
exit;

dc

FiRe

9:30 am on May 14, 2006 (gmt 0)

10+ Year Member



Solved the problem, got rid of the $fp and the loop and just used file_get_contents() instead :)