From 4e550dcdb2aa936955c8736d2216e6a4008e3a37 Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Fri, 16 Feb 2018 11:59:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dnginx=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8sendfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/index/model/FileManage.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/application/index/model/FileManage.php b/application/index/model/FileManage.php index c21bc6c..a2ac1d6 100644 --- a/application/index/model/FileManage.php +++ b/application/index/model/FileManage.php @@ -867,16 +867,30 @@ class FileManage extends Model{ } private function sendFile($speed,$range,$download=false,$header="X-Sendfile"){ + $filePath = ROOT_PATH . 'public/uploads/' . $this->fileData["pre_name"]; + $realPath = ROOT_PATH . 'public/uploads/' . $this->fileData["pre_name"]; + if($header == "X-Accel-Redirect"){ + $filePath = '/public/uploads/' . $this->fileData["pre_name"]; + } if($download){ - $filePath = ROOT_PATH . 'public/uploads/' . $this->fileData["pre_name"]; header('Content-Disposition: attachment; filename="' . str_replace(",","",$this->fileData["orign_name"]) . '"'); header("Content-type: application/octet-stream"); + header('Content-Length: ' .(string)(filesize($realPath)) ); $filePath = str_replace("\\","/",$filePath); + if($header == "X-Accel-Redirect"){ + ob_flush(); + flush(); + echo "s"; + } header($header.": ".str_replace('%2F', '/', rawurlencode($filePath))); }else{ - $filePath = ROOT_PATH . 'public/uploads/' . $this->fileData["pre_name"]; $filePath = str_replace("\\","/",$filePath); - header('Content-Type: '.self::getMimetype($filePath)); + header('Content-Type: '.self::getMimetype($realPath)); + if($header == "X-Accel-Redirect"){ + ob_flush(); + flush(); + echo "s"; + } header($header.": ".str_replace('%2F', '/', rawurlencode($filePath))); ob_flush(); flush(); -- GitLab