PDA

View Full Version : Fread -speed limit - force download


mobilehell
08-24-2005, 04:59 PM
hello everyone
jus wondering how to force download whilst using fread

I found this code to limit the speed it works fine, but when downloading mp3s it streams it instead

$speed = 8.5; // 8,5 kb/s download rate limit

if(file_exists($file) && is_file($file)) {

header("Cache-control: private");
header("Content-Type: application/octet-stream");
header("Content-Length: ".filesize($file));
header("Content-Disposition: filename=$file");

flush();

$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024));
flush();
sleep(1);
}
fclose ($fd);

}

I tried modifying to this

$speed = 8.5; // download rate limit

if(file_exists($file) && is_file($file)) {

header("Pragma: public"); // required
header("Expires: 0");

header('Content-Description: File Transfer');
header("Content-Type: application/force-download");
header("Content-Length: ".filesize($file));
header("Content-Disposition: filename=$file");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
readfile($file);


flush();

$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024));
flush();
sleep(1);
}
fclose ($fd);

}

but now it doesnt limit speed

and also - does anyone know of a way to allow resume using fread

tnx

mobilehell
08-26-2005, 11:03 PM
ok i found out i hd to use sleep(1); to limit speed

can someone help me with resume please