修复nginx无法使用sendfile

This commit is contained in:
HFO4 2018-02-16 11:59:09 +08:00
parent 59f8a9b58d
commit 4e550dcdb2

View file

@ -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();