<?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!');
}
?>

 

相关文章:

  • 2022-12-23
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
猜你喜欢
  • 2022-02-03
  • 2021-11-29
  • 2021-11-12
  • 2021-10-09
  • 2021-12-21
  • 2022-12-23
  • 2021-11-15
相关资源
相似解决方案