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 From 0c24c9242169cfbb3e5dd68f8b094624a2c971f3 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Wed, 15 Jul 2015 20:49:07 +0200 Subject: remove pragma:no-cache header. closes #1201 The pragma header is only defined for requests not for responses. The Cache-Control header should be used in responses. --- inc/fetch.functions.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'inc/fetch.functions.php') diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php index c99fbf20a..b8e75eaec 100644 --- a/inc/fetch.functions.php +++ b/inc/fetch.functions.php @@ -1,4 +1,4 @@ -