冰雨战士

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<?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  冰雨战士  阅读(518)  评论(0编辑  收藏  举报