PHP限制下载速度

<?php
//当前需要下载的文件在服务器上的路径
$local_file='destination.rar';
//设置下载的速度,单位kb/s
$download_speed=20.5;
if(file_exists($local_file) && is_file($local_file)){
     //以附件形式输出
     header('Cache-control: private');
     header('Content-Type: application/octet-stream');
     header('Content-Length: '.filesize($local_file));
     header('Content-Disposition: filename='.strtotime('now'));
     
     //刷新输出缓冲
     flush();
     //打开目标文件
     $file=fopen($local_file,'r');
     while(!feof($file)){
         //每次以round($download_speed*1024字节的速度输出,这是限制下载技术的关键
         print fread($file,round($download_speed*1024));
         flush();
         sleep(1);
     }
}else{
     die($local_file.'does not exist!');
}
?>

 

posted on 2012-12-14 09:20 冰雨战士 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/zfying/archive/2012/12/14/2817469.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值