標籤:ase result ges ati 返回 str code pos close
<?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); } ?>
php檔案下載