2018-09-03 php 限速下载

<?php
/**

  • @author zt6650
  • User: jungle
  • CreateTime: 2018/9/3 9:55

*/

// 将发送到客户端的本地文件
local_file = 'gg.php'; // 文件名download_file = 'gg.php';
// 设置下载速率(=> 20,5 kb/s)
download_rate = 500; 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();
    // 终端1秒后继续
    sleep(1);
}

// 关闭文件流
fclose(file); } else { die('Error: 文件 '.local_file.' 不存在!');
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容