国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php實現(xiàn)下載限制速度示例分享

2024-05-04 23:21:16
字體:
供稿:網(wǎng)友

復制代碼 代碼如下:


// 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!');
}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 开平市| 股票| 襄汾县| 遵义市| 隆德县| 马边| 博乐市| 京山县| 台安县| 长海县| 石狮市| 琼海市| 马龙县| 安岳县| 乌恰县| 大渡口区| 贵南县| 新绛县| 和田市| 寻乌县| 张家口市| 保亭| 清原| 阳江市| 固安县| 开封市| 江口县| 达尔| 星座| 永靖县| 宜川县| 桃园县| 府谷县| 磐石市| 南投市| 含山县| 新营市| 军事| 石景山区| 六盘水市| 长海县|