php下载文件函数
/*@desc:php下载文件函数,支持限速@param name 待下载文件名@param rate 速度,单位kb*/function download($file,$rate=false){set_time_limit(0);$content = file_get_contents($file);$filesize = strlen($content);header ('Content-Length: '.$filesize);header ('Content-type: application/file');header ("Content-Disposition: attachment; filename=".basename($file));if($rate){ ob_start(); $fr=fopen($file,"rb"); while (!feof($fr)){ $data = fread($fr,round($rate*1024)); echo $data; ob_flush(); flush(); sleep(1); } if($fr){ fclose($fr); }}else{ readfile($file);}}
测试:
download('2018.rar',128);
输出:
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。