From a96888c76a5e965388240627602d000a686534e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lucas?= Date: Sat, 19 Jan 2013 06:19:46 +0100 Subject: [PATCH] Change the default config for cops_x_accel_redirect to let PHP handle the download. Should fix problem from KevNancy on IIS. Warning all Nginx users who wants to still use X-Accel-Redirect must add $config['cops_x_accel_redirect'] = "X-Accel-Redirect" in their config_local fix #33 --- README | 2 +- config_default.php | 7 ++++--- fetch.php | 11 ++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README b/README index 2b5ee0c..da32994 100644 --- a/README +++ b/README @@ -121,7 +121,7 @@ configuration (cops_generate_invalid_opds_stream). RewriteOptions inherit RewriteRule ^download/(.*)/.*\.(.*)$ fetch.php?data=$1&type=$2 [L] if you have not mod_xsendfile, in the config file simply set : - $config['cops_x_accel_redirect'] = "location"; + $config['cops_x_accel_redirect'] = "location"; or $config['cops_x_accel_redirect'] = ""; * Cherokee (Thanks to Christophe) : * Add a Behavior of type Regular Expression : /cops/download/(.*)/.*\.(.*)$ diff --git a/config_default.php b/config_default.php index 9f6ce9e..409b68b 100644 --- a/config_default.php +++ b/config_default.php @@ -49,10 +49,11 @@ /* * Wich header to use when downloading books outside the web directory * Possible values are : - * X-Accel-Redirect : For Nginx - * X-Sendfile : For Lightttpd or Apache (with mod_xsendfile) + * X-Accel-Redirect : For Nginx + * X-Sendfile : For Lightttpd or Apache (with mod_xsendfile) + * No value (default) : Let PHP handle the download */ - $config['cops_x_accel_redirect'] = "X-Accel-Redirect"; + $config['cops_x_accel_redirect'] = ""; /* * Height of thumbnail image for OPDS diff --git a/fetch.php b/fetch.php index 325a4c3..e3cefcb 100644 --- a/fetch.php +++ b/fetch.php @@ -97,5 +97,14 @@ } else { header('Content-Disposition: attachment; filename="' . basename ($file) . '"'); } - header ($config['cops_x_accel_redirect'] . ": " . $config['calibre_internal_directory'] . $file); + + if (empty ($config['cops_x_accel_redirect'])) { + $filename = $config['calibre_internal_directory'] . $file; + $fp = fopen($filename, 'rb'); + header("Content-Length: " . filesize($filename)); + fpassthru($fp); + } + else { + header ($config['cops_x_accel_redirect'] . ": " . $config['calibre_internal_directory'] . $file); + } ?> \ No newline at end of file