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(-) (limited to 'inc/fetch.functions.php') 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 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(+) (limited to 'inc/fetch.functions.php') 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 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(-) (limited to 'inc/fetch.functions.php') 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 From 40e0b44409037978b0bce4b451b1569c3bc3ee19 Mon Sep 17 00:00:00 2001 From: Dominik Eckelmann Date: Sat, 15 Feb 2014 10:58:33 +0100 Subject: use http_sendfile correct --- inc/fetch.functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/fetch.functions.php') diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index 3eacaa2fe..c61c54503 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -77,7 +77,7 @@ function sendFile($file, $mime, $dl, $cache, $public = false, $orig = null) { } //use x-sendfile header to pass the delivery to compatible webservers - if(http_sendfile($file)) exit; + http_sendfile($file); // send file contents $fp = @fopen($file, "rb"); -- cgit v1.2.3 From 04585e6c37e0352a5bc568fc8c938aeafa1c160e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerry=20Wei=C3=9Fbach?= Date: Fri, 29 Aug 2014 11:53:19 +0200 Subject: rfc2231 compatible encoding for header() This is only used in the filename header field and ensures correct interpretation of an encoded filename. This is will be needed especially for download of files with umlauts with an Internet Explorer. --- inc/fetch.functions.php | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'inc/fetch.functions.php') diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index c61c54503..55b31a454 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -71,9 +71,9 @@ function sendFile($file, $mime, $dl, $cache, $public = false, $orig = null) { //download or display? if($dl) { - header('Content-Disposition: attachment; filename="'.utf8_basename($orig).'";'); + header('Content-Disposition: attachment;'.rfc2231_encode('filename', utf8_basename($orig)).';'); } else { - header('Content-Disposition: inline; filename="'.utf8_basename($orig).'";'); + header('Content-Disposition: inline;'.rfc2231_encode('filename', utf8_basename($orig)).';'); } //use x-sendfile header to pass the delivery to compatible webservers @@ -89,6 +89,31 @@ function sendFile($file, $mime, $dl, $cache, $public = false, $orig = null) { } } +/** + * Try an rfc2231 compatible encoding. This ensures correct + * interpretation of filenames outside of the ASCII set. + * This seems to be needed for file names with e.g. umlauts that + * would otherwise decode wrongly in IE. + * + * There is no additional checking, just the encoding and setting the key=value for usage in headers + * + * @author Gerry Weissbach + * @param string $name name of the field to be set in the header() call + * @param string $value value of the field to be set in the header() call + * @param string $charset used charset for the encoding of value + * @param string $lang language used. + * @return string in the format " name=value" for values WITHOUT special characters + * @return string in the format " name*=charset'lang'value" for values WITH special characters + */ +function rfc2231_encode($name, $value, $charset='utf-8', $lang='en') { + $internal = preg_replace_callback('/[\x00-\x20*\'%()<>@,;:\\\\"\/[\]?=\x80-\xFF]/', function($match) { return rawurlencode($match[0]); }, $value); + if ( $value != $internal ) { + return ' '.$name.'*='.$charset."'".$lang."'".$internal; + } else { + return ' '.$name.'="'.$value.'"'; + } +} + /** * Check for media for preconditions and return correct status code * -- cgit v1.2.3 From 42ea7f447f39fbc2f79eaaec31f8c10ede59c5d0 Mon Sep 17 00:00:00 2001 From: Gerrit Uitslag Date: Wed, 1 Oct 2014 11:30:27 +0200 Subject: Many PHPDocs, some unused and dyn declared vars many PHPDocs some unused variables some dynamically declared variables declared --- inc/fetch.functions.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'inc/fetch.functions.php') diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index c61c54503..70becc01e 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -16,6 +16,7 @@ * @author Andreas Gohr * @author Ben Coburn * @author Gerry Weissbach + * * @param string $file local file to send * @param string $mime mime type of the file * @param bool $dl set to true to force a browser download @@ -96,12 +97,13 @@ function sendFile($file, $mime, $dl, $cache, $public = false, $orig = null) { * WRITE: MEDIA, FILE, array( STATUS, STATUSMESSAGE ) * * @author Gerry Weissbach + * * @param string $media reference to the media id * @param string $file reference to the file variable * @param string $rev * @param int $width * @param int $height - * @return array(STATUS, STATUSMESSAGE) + * @return array as array(STATUS, STATUSMESSAGE) */ function checkFileStatus(&$media, &$file, $rev = '', $width=0, $height=0) { global $MIME, $EXT, $CACHE, $INPUT; @@ -149,6 +151,9 @@ function checkFileStatus(&$media, &$file, $rev = '', $width=0, $height=0) { * Resolves named constants * * @author Andreas Gohr + * + * @param string $cache + * @return int cachetime in seconds */ function calc_cache($cache) { global $conf; -- cgit v1.2.3 From 79e79377626799a77c11aa7849cb9c64305590c8 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 7 Jan 2015 10:47:45 +0100 Subject: Remove error supression for file_exists() In an older version of PHP a file_exists() call would issue a warning when the file did not exist. This was fixed in later PHP releases. Since we require PHP 5.3 now, there's no need to supress any error here anymore. This might even give a minor performance boost. --- inc/fetch.functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'inc/fetch.functions.php') diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index 3c5bdfeee..c99fbf20a 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -163,7 +163,7 @@ function checkFileStatus(&$media, &$file, $rev = '', $width=0, $height=0) { } //check file existance - if(!@file_exists($file)) { + if(!file_exists($file)) { return array(404, 'Not Found'); } -- cgit v1.2.3