php文件下载

来源:互联网 发布:程序员的思维修炼 txt 编辑:程序博客网 时间:2024/06/06 03:26

php文件下载,很简单的,直接上代码:

<?phpclass FileDownUtils{public function downFile($file_name){//判断文件是否存在if(!file_exists($file_name)){echo "file not found";return;}//打开文件$fp = fopen($file_name, "r");//获取文件大小$file_size = filesize($file_name);//文件类型header("Content-type: application/octet-stream");//请求字段header("Accept-Ranges: bytes");//文件大小header("Accept-Length:".$file_size);//下载框显示的文件名header("Content-Disposition: attachment; filename=".$file_name);//下载速度$buff = 1024;//已经下载的大小$file_count=0;while (!feof($fp) && ($file_size - $file_count) > 0) {$file_data = fread($fp, $buff);$file_count = $file_count+$buff;echo $file_data;}fclose($fp);}}?>


0 0
原创粉丝点击