您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php限制下载速度的实现方法

2024/4/27 12:17:07发布13次查看
20,5 kb/s)
$download_rate = 20.5;if(file_exists($local_file) && is_file($local_file)) {
// send headers header('cache-control: private'); header('content-type: application/octet-stream'); header('content-length: '.filesize($local_file)); header('content-disposition: filename='.$download_file); // flush content
flush(); // open file stream
$file = fopen($local_file, r); while (!feof($file)) { // send the current file part to the browser print fread($file, round($download_rate * 1024)); // flush the content to the browser flush(); // sleep one second sleep(1); } // close file stream fclose($file);}else { die('error: the file '.$local_file.' does not exist!');}?>
复制代码
附:修改discuz论坛实现对附件下载的限速
研究了一下discuz的代码,实现了一个可行的方案。很简单,找到attachment.pnp,找到最下面,有个:function getlocalfile($filename, $readmod = 1, $range = 0)
修改为:
复制代码
经过测试,发现效果还是很明显的。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product