summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerry Weißbach <gerry.w@gammaproduction.de>2014-08-29 11:53:19 +0200
committerGerry Weißbach <gerry.w@gammaproduction.de>2014-08-29 11:53:19 +0200
commit04585e6c37e0352a5bc568fc8c938aeafa1c160e (patch)
tree9aa146e1a4722934ffff5359c5f21b99c314ff1d
parent0bd5b90b4c1294b3c9abc1977060f971dc2e2744 (diff)
downloadrpg-04585e6c37e0352a5bc568fc8c938aeafa1c160e.tar.gz
rpg-04585e6c37e0352a5bc568fc8c938aeafa1c160e.tar.bz2
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.
-rw-r--r--inc/fetch.functions.php29
1 files changed, 27 insertions, 2 deletions
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
@@ -90,6 +90,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 <gerry.w@gammaproduction.de>
+ * @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
*
* READ: MEDIA, MIME, EXT, CACHE