我找到了一个允许限制文件下载速度的脚本here。
// The file that will be sent to the user
$your_file = 'file.zip';
// Rename the file name
$new_file = 'new-filename.zip';
// Set the download speed limit (70 kb/s)
$download_speed = 70;
if(file_exists($myl_file) && is_file($my_file)) {
// Headers
header('Cache-control: private');
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($my_file));
header('Content-Disposition: filename='.$new_file);
// Flush the content
flush();
// File stream
$file = fopen($my_file, "r");
while (!feof($file)) {
// Send the current part of the file to the browser
echo fread($file, round($download_speed* 1024));
// Flush the content to the browser
flush();
// Sleep one second
sleep(1);
}
// Close file stream
fclose($file);
}
else {
die('Error: The file '.$my_file.' does not exist!');
}
问题是速度限制不起作用(但我可以下载文件)当我更改$ download_speed值时,我总是在1500-2000 kb / s之间。我在wamp和webserver上测试它但不可能使它工作。有任何想法吗?谢谢你。