<?php /* *下载报告 */ public function down_report(){ /* $result = array("error"=>1,"content"=>''); if(!session('user_id')) { $result['error'] = -1; $result['content'] = "请先登录"; $result['url'] = "/mobile/user/login"; $this->showMsg($result); } $url = yf_empty($_POST['url'], '', true); if(!$url) { $result['content'] = "非法参数"; $this->showMsg($result); } */ /* if(1==1){ $result['error'] = 1; $result['content'] = $url; $this->showMsg($result); } */ /* 下载开始 */ $url = yf_empty($_GET['url'], '', true); if(!$url){ echo "文件参数错误"; exit; } $filename = basename($url); //文件名 $filepath = $_SERVER['DOCUMENT_ROOT'].$url; //文件绝对路径 if(!file_exists($filepath)){ $result['error'] = 1; $result['content'] = "文件不存在"; } $fp = fopen($filepath,"r+"); //打开文件流 $filesize = filesize($filepath); //$filearr = explode(".",$filename); //$prefix = $filearr[0]; //文件前缀 //$suxfix = $filearr[1]; //文件后缀 header("Content-Type:application/octet-stream"); header("Accept-Ranges:bytes"); header("Accept-Length:".$filesize); header("Content-Disposition:attachment;filename=".$filename); header("Pragma:no-cache"); //不缓存 header("Expires:0"); $buffer=1024; $filecount=0; //向浏览器返回数据 while(!feof($fp) && $filecount<$filesize){ $filecon = fread($fp,$buffer); $filecount += $buffer; echo $filecon; } fclose($fp); } ?>