php實現(xiàn)下載限制速度示例分享
// 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!');
}
相關文章
用HTML/JS/PHP方式實現(xiàn)頁面延時跳轉的簡單實例
下面小編就為大家?guī)硪黄肏TML/JS/PHP方式實現(xiàn)頁面延時跳轉的簡單實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07
在Ubuntu 14.04上部署 PHP 環(huán)境及 WordPress
Ubuntu確實很好玩。有喜歡的命令行,簡潔的界面,不同于Window要的感覺。偶爾換換環(huán)境工作,學習Linux的思維方式,是一種不錯的做法。之前也折騰過Ubuntu,想在Linux下學習某些開發(fā)(主要還是和代碼打交道),Ubuntu當然是最好不過的選擇,并且剛發(fā)布了14.04版本2014-09-09
Laravel 5框架學習之向視圖傳送數(shù)據(jù)
本文向大家展示的是Laravel5框架學習系列的第三篇文章,給大家講解的是如何向視圖傳送數(shù)據(jù),從無到有,十分細致,有需要的小伙伴可以參考下。2015-04-04

