使用PHP限制下载速度
我这里有这段代码,但是我想限制用户可以下载的速度,我将如何在这段代码中实现这一点使用PHP限制下载速度,php,header,Php,Header,我这里有这段代码,但是我想限制用户可以下载的速度,我将如何在这段代码中实现这一点 header("Content-type: application/force-download"); header("Content-Transfer-Encoding: Binary"); header("Content-length: ".filesize("uploads/$filename")); header("Content-disposition: attachment; f
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize("uploads/$filename"));
header("Content-disposition: attachment; filename=\"$origname");
readfile("uploads/$filename");
谢谢
这就是我所尝试的
$download_rate = 100;
$origname=get_file_name($file[0])
//刷新内容
冲洗()
为什么不起作用?希望这有帮助如果您尝试了@mugur建议的方法,那么其他地方可能会有问题。例如,在您的代码片段中,似乎缺少一个转义引号: 标题(“内容处置:附件;文件名=\”$origname”) 我想应该是: 标题(“内容处置:附件;文件名=\”$origname\”)
在你的while fread中,只需计算字节和时间戳。然后使用usleep添加一个小暂停。是的,我读过这篇文章,但是我确实需要一种方法来整合它,因为我已经尝试过了,但失败了!好吧,你尝试了什么?它是如何失败的?这似乎是一个很好的起点,所以不要要求每个人都重新做你已经做过的事情。这会给你一个机会吗错误,它下载得更快,或者是怎么失败的?好吧,基本上,下载限制是有效的,但它不显示文件下载,只是在后台下载,并在完成后说它完成了。是的,因为文件可能是以特定的“下载速率”放在服务器端的“然后发送到您的浏览器。要开始下载并使其显示为有限下载,您需要通过Apache配置进行下载,一个好的起点是:
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize("uploads/$filename"));
header("Content-disposition: attachment; filename=\'$origname'");
$local_file = "uploads/$origname";
// open file stream
$file = fopen($local_file, "r");
while (!feof($file)) {
// send the current file part to the browser
print fread($file, round($download_rate * 1024));
// flush the content to the browser
flush();
// sleep one second
sleep(1);
}
// close file stream
fclose($file);