I've been playing around with this snippet of code I found that theoretically is suppose to limit the download speed from the browser to whatever amount I specify. However it seems no matter what it is limiting the speed to about 8.5 to 9kb/sPHP Code:function getext($file) {
return $ext=substr(strrchr($file, '.'), 1);
}
function filesize_url($url){
return ($data = @file_get_contents($url)) ? strlen($data) : false;
}
function sendfile($filename) {
global $type,$set,$ext;
$file="http://www.some-site.net/".$filename;
$ext=getext($filename);
$mtype=$type[$ext][type];
if(ini_get('zlib.output_compression')) {ini_set('zlib.output_compression', 'Off');}
flush();
$file_size = filesize_url($file);
$fp = fopen($file, 'r');
header('Expires: 0');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: $mtype");
header("Accept-Ranges: bytes");
#header("Content-Disposition: attachment; filename=\"" . $filename ."\"");
$user_agent = strtolower ($_SERVER['HTTP_USER_AGENT']);
if ((is_integer (strpos($user_agent, "msie"))) && (is_integer (strpos($user_agent, "win")))) {
header( "Content-Disposition: filename=".basename($filename).";" );
} else {
header( "Content-Disposition: attachment; filename=".basename($filename).";");
}
header("Content-transfer-encoding: binary");
header("Content-Length: $file_size");
flush();
$speed=round(25*1024);
while (!feof($fp))
{
set_time_limit(0);
print(fread($fp, $speed));
flush();
sleep(1);
} //end while
fclose ($fp);
die;
}
sendfile("testfile.exe");
Eventhough I have it set to download at 25kb/s. Any ideas as to whats wrong or a way to limit the speed of a file download that is located remotely?


Reply With Quote
