php文件上传速度,PHP控制文件下载速度

ddb2e6ddeb313cb1a6edb3ff7ce1d0bb.pngPHP控制文件下载速度

发表于 2015-12-24 / 1797 次围观

// 将发送到客户端的本地文件

$local_file = 'test-file.zip';

// 文件名

$download_file = 'your-download-name.zip';

// 设置下载速率(=> 20,5 kb/s)

$download_rate = 20.5;

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

// 发送 headers

header('Cache-control: private');

header('Content-Type: application/octet-stream');

header('Content-Length: '.filesize($local_file));

header('Content-Disposition: filename='.$download_file);

// flush 内容

flush();

// 打开文件流

$file = fopen($local_file, "r");

while (!feof($file)) {

// 发送当前部分文件给浏览者

print fread($file, round($download_rate * 1024));

// flush 内容输出到浏览器端

flush();

ob_flush(); //防止PHP或web服务器的缓存机制影响输出

// 终端1秒后继续

sleep(1);

}

// 关闭文件流

fclose($file);

}

else {

die('Error: 文件 '.$local_file.' 不存在!');

}

标签: PHP

d1ef3032eb6442748ea47f3defc35ec4.png

技术宅,科技怪,程序猿。

Comments : 0

有问题可在下面发表评论,当然没事也可以在下面吹吹牛皮、扯扯淡!

昵称 *

邮箱 *

网址

c556d7d6fbd8357624e19a6903f92f83.gif44f1c096d76cdb1071bf2c117c2655c0.gif963f8333002321d06f4331e8c041b1aa.gif4f6754ea706ab583116912872543e791.gif5f1e21648a49bd83913dd2a7d7ba9f34.gif8acdb2fa2be634150a531cbb29d4b7ba.gifbe1c10b7e6912770d721da772efd8fc2.gif8f6123f6480d96e985d60637a7361716.gifeeeea366e1971fe2c76c3b923a923779.gifaa7ad653ae0bc6654105d27a219c3155.gif14c4dcf73a3ee2c7b434c56f7e38662b.gife151df8eb9f6bd94696edf282a1652ad.gifa817ea9369377b5218d25de58bd2b390.gifc22ad2e6d4ab9964da5d0fb36e7efc2e.gif706882f93475cbca9fafa72e441b7123.gifdca87d71aa77259a9e5ce04b96c6e12e.gif49b662beadf8e164173b130f536718a6.gife7b1e44e201afcdff357d21a7c80d130.gifaba55f9d432a92bfc0e5f9baba330edd.gifbe42574b8e5545909248d115b7b55447.gif8adcc25ab3622e50c39f96f31f6668a7.giff40f085aaa18e070db8610ef7a733fa4.gif

ecffb7a5689390f7803a116601d0b0ed.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值