<?php //当前需要下载的文件在服务器上的路径 $local_file='destination.rar'; //设置下载的速度,单位kb/s $download_speed=20.5; if(file_exists($local_file) && is_file($local_file)){ //以附件形式输出 header('Cache-control: private'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($local_file)); header('Content-Disposition: filename='.strtotime('now')); //刷新输出缓冲 flush(); //打开目标文件 $file=fopen($local_file,'r'); while(!feof($file)){ //每次以round($download_speed*1024字节的速度输出,这是限制下载技术的关键 print fread($file,round($download_speed*1024)); flush(); sleep(1); } }else{ die($local_file.'does not exist!'); } ?>