From 32c584aadfbf4d297dbea400e69a0255614ff542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerry=20Wei=C3=9Fbach?= Date: Mon, 27 Jan 2014 10:07:59 +0100 Subject: Use original filename for Content-Disposition In most cases this change will have no effect, but noes the response will use the filename that was originally requested. The downloaded filename can be modified to something different as well. E.g. the siteexport plugin will make use of it. --- inc/fetch.functions.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index 207ad9e5f..3e563b324 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -16,12 +16,13 @@ * @author Andreas Gohr * @author Ben Coburn * @param string $file local file to send + * @param string $orig original file to send - the file name will be used for the Content-Disposition * @param string $mime mime type of the file * @param bool $dl set to true to force a browser download * @param int $cache remaining cache time in seconds (-1 for $conf['cache'], 0 for no-cache) * @param bool $public is this a public ressource or a private one? */ -function sendFile($file, $mime, $dl, $cache, $public = false) { +function sendFile($file, $orig, $mime, $dl, $cache, $public = false) { global $conf; // send mime headers header("Content-Type: $mime"); @@ -64,9 +65,9 @@ function sendFile($file, $mime, $dl, $cache, $public = false) { //download or display? if($dl) { - header('Content-Disposition: attachment; filename="'.utf8_basename($file).'";'); + header('Content-Disposition: attachment; filename="'.utf8_basename($orig).'";'); } else { - header('Content-Disposition: inline; filename="'.utf8_basename($file).'";'); + header('Content-Disposition: inline; filename="'.utf8_basename($orig).'";'); } //use x-sendfile header to pass the delivery to compatible webservers -- cgit v1.2.3 From d2affc245d260133a8e9734ad309e5ceba8f42b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerry=20Wei=C3=9Fbach?= Date: Mon, 27 Jan 2014 10:08:48 +0100 Subject: Use original filename for Content-Disposition In most cases this change will have no effect, but noes the response will use the filename that was originally requested. The downloaded filename can be modified to something different as well. E.g. the siteexport plugin will make use of it. --- lib/exe/fetch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index f33b3f2f8..16426938f 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -89,7 +89,7 @@ if (defined('SIMPLE_TEST')) { // finally send the file to the client $evt = new Doku_Event('MEDIA_SENDFILE', $data); if($evt->advise_before()) { - sendFile($data['file'], $data['mime'], $data['download'], $data['cache'], $data['ispublic']); + sendFile($data['file'], $data['orig'], $data['mime'], $data['download'], $data['cache'], $data['ispublic']); } // Do something after the download finished. $evt->advise_after(); // will not be emitted on 304 or x-sendfile -- cgit v1.2.3 From 499df7e58de676339d1267e82dc44238db31c210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerry=20Wei=C3=9Fbach?= Date: Mon, 27 Jan 2014 10:12:55 +0100 Subject: nop --- inc/fetch.functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index 3e563b324..d36407848 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -15,6 +15,7 @@ * * @author Andreas Gohr * @author Ben Coburn + * @author Gerry Weissbach * @param string $file local file to send * @param string $orig original file to send - the file name will be used for the Content-Disposition * @param string $mime mime type of the file -- cgit v1.2.3 From a0e46368e9ad87d959bd921504ced42bc3d5b4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerry=20Wei=C3=9Fbach?= Date: Mon, 27 Jan 2014 10:21:08 +0100 Subject: Re-order parameters to not break other callers --- lib/exe/fetch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index 16426938f..5f82ad0e0 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -89,7 +89,7 @@ if (defined('SIMPLE_TEST')) { // finally send the file to the client $evt = new Doku_Event('MEDIA_SENDFILE', $data); if($evt->advise_before()) { - sendFile($data['file'], $data['orig'], $data['mime'], $data['download'], $data['cache'], $data['ispublic']); + sendFile($data['file'], $data['mime'], $data['download'], $data['cache'], $data['ispublic'], $data['orig']); } // Do something after the download finished. $evt->advise_after(); // will not be emitted on 304 or x-sendfile -- cgit v1.2.3 From 2fd6745d5fd3a6b5b4b5a0a1952826095e35dac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerry=20Wei=C3=9Fbach?= Date: Mon, 27 Jan 2014 10:22:37 +0100 Subject: Re-order parameters to not break other callers Needs a check for null now. --- inc/fetch.functions.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index d36407848..3eacaa2fe 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -17,13 +17,13 @@ * @author Ben Coburn * @author Gerry Weissbach * @param string $file local file to send - * @param string $orig original file to send - the file name will be used for the Content-Disposition * @param string $mime mime type of the file * @param bool $dl set to true to force a browser download * @param int $cache remaining cache time in seconds (-1 for $conf['cache'], 0 for no-cache) * @param bool $public is this a public ressource or a private one? + * @param string $orig original file to send - the file name will be used for the Content-Disposition */ -function sendFile($file, $orig, $mime, $dl, $cache, $public = false) { +function sendFile($file, $mime, $dl, $cache, $public = false, $orig = null) { global $conf; // send mime headers header("Content-Type: $mime"); @@ -64,6 +64,11 @@ function sendFile($file, $orig, $mime, $dl, $cache, $public = false) { $fmtime = @filemtime($file); http_conditionalRequest($fmtime); + // Use the current $file if is $orig is not set. + if ( $orig == null ) { + $orig = $file; + } + //download or display? if($dl) { header('Content-Disposition: attachment; filename="'.utf8_basename($orig).'";'); -- cgit v1.2.3