php實(shí)現(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!');
}
相關(guān)文章
用HTML/JS/PHP方式實(shí)現(xiàn)頁面延時(shí)跳轉(zhuǎn)的簡單實(shí)例
下面小編就為大家?guī)硪黄肏TML/JS/PHP方式實(shí)現(xiàn)頁面延時(shí)跳轉(zhuǎn)的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-07-07
thinkPHP框架實(shí)現(xiàn)生成條形碼的方法示例
這篇文章主要介紹了thinkPHP框架實(shí)現(xiàn)生成條形碼的方法,結(jié)合實(shí)例形式分析了thinkPHP結(jié)合第三方barcode類文件生成條形碼的相關(guān)操作技巧,需要的朋友可以參考下2018-06-06
在Ubuntu 14.04上部署 PHP 環(huán)境及 WordPress
Ubuntu確實(shí)很好玩。有喜歡的命令行,簡潔的界面,不同于Window要的感覺。偶爾換換環(huán)境工作,學(xué)習(xí)Linux的思維方式,是一種不錯(cuò)的做法。之前也折騰過Ubuntu,想在Linux下學(xué)習(xí)某些開發(fā)(主要還是和代碼打交道),Ubuntu當(dāng)然是最好不過的選擇,并且剛發(fā)布了14.04版本2014-09-09
ThinkPHP分組下自定義標(biāo)簽庫實(shí)例
這篇文章主要介紹了ThinkPHP分組下自定義標(biāo)簽庫的方法,以實(shí)例形式講述了自定義標(biāo)簽庫的具體步驟,非常具有參考借鑒價(jià)值,需要的朋友可以參考下2014-11-11
Laravel獲取當(dāng)前請(qǐng)求的控制器和方法以及中間件的例子
今天小編就為大家分享一篇Laravel獲取當(dāng)前請(qǐng)求的控制器和方法以及中間件的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10
Laravel 5框架學(xué)習(xí)之向視圖傳送數(shù)據(jù)
本文向大家展示的是Laravel5框架學(xué)習(xí)系列的第三篇文章,給大家講解的是如何向視圖傳送數(shù)據(jù),從無到有,十分細(xì)致,有需要的小伙伴可以參考下。2015-04-04

