我在这里有这段代码,但是我想限制用户下载的速度,我如何在这段代码中实现这一点;
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);
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";// flush content flush();
// 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);为什么这个不起作用?
发布于 2012-01-29 07:56:51
如果你已经尝试了@mugur建议的方法,那么在其他地方可能会有问题。例如,在您的代码片段中,似乎有一个缺失的转义引号:
header("Content-disposition:附件;filename=\"$origname");
我想应该是:
header("Content-disposition:附件;filename=\"$origname\"");
发布于 2012-01-29 07:48:19
希望这能对http://www.jonasjohn.de/snippets/php/dl-speed-limit.htm有所帮助
发布于 2012-01-29 08:52:16
在while fread中,只计算字节和时间戳。然后使用usleep添加一个小小的停顿。
https://stackoverflow.com/questions/9049634
复制相似问题