zoukankan      html  css  js  c++  java
  • 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!');
    }
    ?>
  • 相关阅读:
    HDU
    HDU
    HDU
    HDU
    HDU
    P6146 [USACO20FEB]Help Yourself G 组合数学 DP
    CodeForces
    POJ
    【网络学习】集线器,交换机,路由器的作用
    【Python学习】深拷贝和浅拷贝
  • 原文地址:https://www.cnblogs.com/zfying/p/2817469.html
Copyright © 2011-2022 走看看