我发现这个伟大的脚本从目录中下载和保护文件:如何为此php脚本添加下载速度限制?
http://www.gowondesigns.com/?page.getfile
我看到这个代码从一个网站太:
// local file that should be send to the client
$local_file = 'test-file.zip';
// filename that the user gets as default
$download_file = 'your-download-name.zip';
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5;
if(file_exists($local_file) && is_file($local_file)) {
// send headers
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($local_file));
header('Content-Disposition: filename='.$download_file);
// 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);
}
else {
die('Error: The file '.$local_file.' does not exist!');
}
我怎样才能将它们组合起来?我的意思是我如何使用getfile脚本并为其添加下载速率?
我尝试添加:
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);
}
但不是$文件,我想应该是$ fd和我没有任何积极的结果
我在做什么错?
为什么不只是使用您提供的脚本,除文件外不更改任何内容?你在上面复制了什么,在实际的解决方案下面甚至没有打开文件,也没有发送头文件等等。 – MrJ 2012-02-13 08:15:28
哪一个,Getfile是我在Google找到的?对我来说,他们都似乎工作正常,但我想添加打印fread($ file,round($ download_rate * 1024));函数到http://www.gowondesigns.com/?page.getfile – 2012-02-14 00:16:14