diff options
author | Andreas Gohr <andi@splitbrain.org> | 2007-10-08 20:50:19 +0200 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2007-10-08 20:50:19 +0200 |
commit | 9a87c72a533121b83c56075947a3e27c853b2188 (patch) | |
tree | 9526b7fe6e2568bd5dfc739e97ecddfc93252c62 /lib/exe | |
parent | 1462e3ae97d9af23cc143bfaf7a48143673b3d40 (diff) | |
download | rpg-9a87c72a533121b83c56075947a3e27c853b2188.tar.gz rpg-9a87c72a533121b83c56075947a3e27c853b2188.tar.bz2 |
X-Sendfile support for fetch.php
This patch enables the use of the X-Sendfile extension offered by certain
webservers to deliver static files after running a dynamic script. This
combines the flexibility of a PHP file to check for authorization, caching
and resizing with the low memory footprint and high performance of static
file delivery of the webserver.
See http://blog.lighttpd.net/articles/2006/07/02/x-sendfile for details
darcs-hash:20071008185019-7ad00-1e6d4768fb60d58955e4253c7786eaf8cf13d0bb.gz
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/fetch.php | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index 71ec2870b..d29ed9f64 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -104,16 +104,28 @@ function sendFile($file,$mime,$cache){ header('Cache-Control: must-revalidate, no-transform, post-check=0, pre-check=0'); header('Pragma: public'); } - header('Accept-Ranges: bytes'); //send important headers first, script stops here if '304 Not Modified' response http_conditionalRequest($fmtime); - list($start,$len) = http_rangeRequest(filesize($file)); + //application mime type is downloadable if(substr($mime,0,11) == 'application'){ header('Content-Disposition: attachment; filename="'.basename($file).'";'); } + //use x-sendfile header to pass the delivery to compatible webservers + if($conf['xsendfile'] == 1){ + header("X-LIGHTTPD-send-file: $file"); + exit; + }elseif($conf['xsendfile'] == 2){ + header("X-Sendfile: $file"); + exit; + } + + //support download continueing + header('Accept-Ranges: bytes'); + list($start,$len) = http_rangeRequest(filesize($file)); + // send file contents $fp = @fopen($file,"rb"); if($fp){ |