首页 / PHP / 使用PHP限制下载速度_PHP教程
使用PHP限制下载速度_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了使用PHP限制下载速度_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1432字,纯文字阅读大概需要3分钟。
内容图文
各位做运维的童鞋,会经常遇到一个问题,那就是有人再办公室下载东西,影响大家上网、办公。同样的问题,要是出现在了服务器上面,估计会让老板发火,事情发展的会更糟……今天特此想大家推荐几行关于PHP限制网速的代码,希望给大家一些帮助。[代码] [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
(
$file
,
round
(
$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
}
http://www.bkjia.com/PHPjc/735162.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/735162.htmlTechArticle各位做运维的童鞋,会经常遇到一个问题,那就是有人再办公室下载东西,影响大家上网、办公。同样的问题,要是出现在了服务器上面,...
内容总结
以上是互联网集市为您收集整理的使用PHP限制下载速度_PHP教程全部内容,希望文章能够帮你解决使用PHP限制下载速度_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。