php限制文件下载速度代码
2016-03-21 11:08
731 查看
php限制文件下载速度代码
<?php /* Source: http://www.apphp.com/index.php?snippet=php-download-file-with-speed-limit */ /* set here a limit of downloading rate (e.g. 10.20 Kb/s) */ $download_rate = 10.20; $download_file = 'download-file.zip'; $target_file = 'target-file.zip'; if(file_exists($download_file)){ /* headers */ header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); header('Cache-control: private'); header('Content-Type: application/octet-stream'); //HTTP Content-type ( 二进制流,不知道下载文件类型) header('Content-Length: '.filesize($download_file)); header('Content-Disposition: filename='.$target_file); /* flush content */ flush(); /* open file */ $fh = @fopen($download_file, 'r'); while(!feof($fh)){ /* send only current part of the file to browser */ print fread($fh, round($download_rate * 1024)); /* flush the content to the browser */ flush(); /* sleep for 1 sec */ sleep(1); } /* close file */ @fclose($fh); }else{ die('Fatal error: the '.$download_file.' file does not exist!'); } ?>
相关文章推荐
- php常用正则表达式
- 最常用的PHP正则表达式收集整理
- 解决PHP超大文件下载,断点续传下载的方法详解
- 关于PHP中浏览器禁止Cookie后,Session能使用吗?
- php强制文件下载(避免文件或图片直接在浏览器中打开)
- php进阶:cookie的有效路径
- php中,error_reporting(E_ALL || ~E_NOTICE)是何意?
- 【转载】调用dede:sql,dede:php标签 调用文章的静态链接地址
- Zend Framework实现多文件上传功能实例
- 一个经典实用的PHP图像处理类
- 【转载】dedecms中的{dede:php}{/dede:php}的详细用法
- PHP进阶:cookie的删除与过期时间
- 通过PHP current函数获取未知字符键名数组第一个元素的值
- 【转载】php list,each 函数
- PHP数组内部的指针函数
- php数组指针如何移动到指定单元?
- PHP array_slice() 函数
- PHP中JSON的应用
- DedeCMS Error:Tag disabled:php错误的完整处理方法_DedeCms教程
- 【php】assert函数的用法