我这里有这个代码,但是我想限制用户可以下载的速度,我将如何在此代码中实现此代码;
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]);
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);
为什么这不起作用?
答案 0 :(得分:1)
答案 1 :(得分:1)
如果您尝试过@mugur建议的话,那么其他地方可能会出现问题。例如,在您的代码段中,您似乎找到了丢失的转义引号:
标题(“Content-disposition:attachment; filename = \”$ origname“);
我想它应该是:
标题(“Content-disposition:attachment; filename = \”$ origname \“”);
答案 2 :(得分:0)
在你的fread中,只需计算字节和时间戳。然后使用usleep添加一个微小的暂停。