From 67549c71b8be00c7ef570b6054855a13861d9722 Mon Sep 17 00:00:00 2001 From: Etienne CHAMPETIER Date: Thu, 18 Jul 2013 15:09:27 +0200 Subject: [PATCH] Add X-Accel-Redirect support for Nginx (a sibiling of X-Sendfile) For it to work you have to modify your nginx conf to send X-Accel-Mapping header using -> proxy_set_header X-Accel-Mapping /var/www/ajaxplorer/data/=/data/; or -> fastcgi_param X-Accel-Mapping /var/www/ajaxplorer/data/=/data/; and you have to use the "internal" keyword -> location ~ /data/ { internal; } The X-Accel-Mapping idea come from the rails world --- .../plugins/access.fs/class.fsAccessDriver.php | 16 ++++++++++++++++ core/src/plugins/access.fs/manifest.xml | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/src/plugins/access.fs/class.fsAccessDriver.php b/core/src/plugins/access.fs/class.fsAccessDriver.php index 9861e8b77e..42823f8a43 100644 --- a/core/src/plugins/access.fs/class.fsAccessDriver.php +++ b/core/src/plugins/access.fs/class.fsAccessDriver.php @@ -1236,6 +1236,22 @@ function readFile($filePathOrData, $headerType="plain", $localName="", $data=fal header('Content-Disposition: attachment; filename="' . basename($filePathOrData) . '"'); return; } + if($this->getFilteredOption("USE_XACCELREDIRECT", $this->repository->getId()) && $this->wrapperClassName == "fsAccessWrapper" && array_key_exists("X-Accel-Mapping",$_SERVER)){ + if(!$realfileSystem) $filePathOrData = fsAccessWrapper::getRealFSReference($filePathOrData); + $filePathOrData = str_replace("\\", "/", $filePathOrData); + $filePathOrData = SystemTextEncoding::toUTF8($filePathOrData); + $mapping = explode('=',$_SERVER['X-Accel-Mapping']); + $replacecount = 0; + $accelfile = str_replace($mapping[0],$mapping[1],$filePathOrData,$replacecount); + if($replacecount == 1){ + header("X-Accel-Redirect: $accelfile"); + header("Content-type: application/octet-stream"); + header('Content-Disposition: attachment; filename="' . basename($accelfile) . '"'); + return; + } else { + AJXP_Logger::logAction("error","Problem with X-Accel-Mapping for file $filePathOrData"); + } + } $stream = fopen("php://output", "a"); if($realfileSystem){ AJXP_Logger::debug("realFS!", array("file"=>$filePathOrData)); diff --git a/core/src/plugins/access.fs/manifest.xml b/core/src/plugins/access.fs/manifest.xml index 9c75565969..e78c93879b 100644 --- a/core/src/plugins/access.fs/manifest.xml +++ b/core/src/plugins/access.fs/manifest.xml @@ -14,6 +14,7 @@ + @@ -38,4 +39,4 @@ - \ No newline at end of file +