使用 PHP 限制下载速度_PHP教程

php中文网
发布: 2016-07-13 10:37:41
原创
931人浏览过

各位做运维的童鞋,会经常遇到一个问题,那就是有人再办公室下载东西,影响大家上网、办公。同样的问题,要是出现在了服务器上面,估计会让老板发火,事情发展的会更糟……今天特此想大家推荐几行关于PHP限制网速的代码,希望给大家一些帮助。

某化妆品公司网站1.1
某化妆品公司网站1.1

1、演示:以截图为准(已测试)2、本源码为phpweb整站打包3、作者主页:http://www.juchake.com4、关于程序安装: 本源码均为作者亲自测试过,可以正常使用,无限制,为了大家的方便安装,作者还特意录制了安装视频教程,不懂的可以学习教程后安装,谢谢,多多支持。由于是视频教程不好上传,大家到百度云下载即可http://pan.baidu.com/share/link?shar

某化妆品公司网站1.1 0
查看详情 某化妆品公司网站1.1

[代码] [PHP]代码

view source print? 01 // local file that should be send to the client 02 $local_file 'test-file.zip'; 03   04 // filename that the user gets as default 05 $download_file 'your-download-name.zip'; 06   07 // set the download rate limit (=> 20,5 kb/s) 08 $download_rate = 20.5; 09   10 if(file_exists($local_file) && is_file($local_file)) { 11   12  // send headers 13  header('Cache-control: private'); 14  header('Content-Type: application/octet-stream'); 15  header('Content-Length: '.filesize($local_file)); 16  header('Content-Disposition: filename='.$download_file); 17   18  // flush content 19  flush(); 20   21  // open file stream 22  $file fopen($local_file"r"); 23   24  while (!feof($file)) { 25   26  // send the current file part to the browser 27  print fread($fileround($download_rate * 1024)); 28   29  // flush the content to the browser 30  flush(); 31   32  // sleep one second 33  sleep(1); 34  } 35   36  // close file stream 37  fclose($file); 38   39 } 40   41 else { 42  die('Error: The file '.$local_file.' does not exist!'); 43 }

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/735162.htmlTechArticle各位做运维的童鞋,会经常遇到一个问题,那就是有人再办公室下载东西,影响大家上网、办公。同样的问题,要是出现在了服务器上面,...
相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号