国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 宣城市| 盐边县| 阿拉善右旗| 资阳市| 昭平县| 东乡县| 洪雅县| 丰台区| 英德市| 枣阳市| 大关县| 阳原县| 保亭| 永吉县| 广饶县| 喀喇| 汝南县| 延津县| 申扎县| 水城县| 彰化市| 马龙县| 平南县| 安新县| 海城市| 宁南县| 井冈山市| 大庆市| 荣昌县| 伊川县| 历史| 武乡县| 汉阴县| 西林县| 景宁| 南华县| 当雄县| 扶绥县| 来宾市| 余干县| 伽师县|