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!');
}
相關(guān)文章
PHP生成json和xml類型接口數(shù)據(jù)格式
在做數(shù)據(jù)接口時,我們通常要獲取第三方數(shù)據(jù)接口或者給第三方提供數(shù)據(jù)接口,而這些數(shù)據(jù)格式通常是以XML或者JSON格式傳輸,本文將介紹如何使用PHP生成XML格式數(shù)據(jù)供第三方調(diào)用以及如何獲取第三方提供的XML數(shù)據(jù)。2015-05-05利用 fsockopen() 函數(shù)開放端口掃描器的實例
下面小編就為大家?guī)硪黄?fsockopen() 函數(shù)開放端口掃描器的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-08-08淺談php數(shù)組array_change_key_case() 函數(shù)和array_chunk()函數(shù)
下面小編就為大家?guī)硪黄獪\談php數(shù)組array_change_key_case() 函數(shù)和array_chunk()函數(shù)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10ThinkPHP類似AOP思想的參數(shù)驗證的實現(xiàn)方法
這篇文章主要介紹了ThinkPHP類似AOP思想的參數(shù)驗證的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12