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)文章
PHP生成json和xml類型接口數(shù)據(jù)格式
在做數(shù)據(jù)接口時(shí),我們通常要獲取第三方數(shù)據(jù)接口或者給第三方提供數(shù)據(jù)接口,而這些數(shù)據(jù)格式通常是以XML或者JSON格式傳輸,本文將介紹如何使用PHP生成XML格式數(shù)據(jù)供第三方調(diào)用以及如何獲取第三方提供的XML數(shù)據(jù)。2015-05-05
利用 fsockopen() 函數(shù)開(kāi)放端口掃描器的實(shí)例
下面小編就為大家?guī)?lái)一篇利用 fsockopen() 函數(shù)開(kāi)放端口掃描器的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08
php微信公眾號(hào)開(kāi)發(fā)之校園圖書(shū)館
這篇文章主要為大家詳細(xì)介紹了php微信公眾號(hào)開(kāi)發(fā)之校園圖書(shū)館,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10
php微信公眾平臺(tái)開(kāi)發(fā)(一) 配置接口
這篇文章主要為大家詳細(xì)介紹了php微信公眾平臺(tái)開(kāi)發(fā)第一篇,微信公眾號(hào)配置接口,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12
淺談php數(shù)組array_change_key_case() 函數(shù)和array_chunk()函數(shù)
下面小編就為大家?guī)?lái)一篇淺談php數(shù)組array_change_key_case() 函數(shù)和array_chunk()函數(shù)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
ThinkPHP類似AOP思想的參數(shù)驗(yàn)證的實(shí)現(xiàn)方法
這篇文章主要介紹了ThinkPHP類似AOP思想的參數(shù)驗(yàn)證的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12

