summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2014-12-22 11:09:59 +0100
committerAndreas Gohr <andi@splitbrain.org>2014-12-22 11:09:59 +0100
commitc0837f71ab81685a26a7bc12bd7508079e986a95 (patch)
tree9c63975e3898c949e1784e30e81a5ed3da7fca93
parent1bf4abb07f65e28578bae98aad457cb768d8b44f (diff)
parent8da2ebf4f4261eb8f54df5704b5d9af283b5402d (diff)
downloadrpg-c0837f71ab81685a26a7bc12bd7508079e986a95.tar.gz
rpg-c0837f71ab81685a26a7bc12bd7508079e986a95.tar.bz2
Merge pull request #845 from gamma/master
rfc2231 compatible encoding for header()
-rw-r--r--inc/fetch.functions.php29
-rw-r--r--inc/init.php4
2 files changed, 29 insertions, 4 deletions
diff --git a/inc/fetch.functions.php b/inc/fetch.functions.php
index 70becc01e..3c5bdfeee 100644
--- a/inc/fetch.functions.php
+++ b/inc/fetch.functions.php
@@ -72,9 +72,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
@@ -91,6 +91,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
diff --git a/inc/init.php b/inc/init.php
index d0d9101e6..12bb6f588 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -429,7 +429,7 @@ function getBaseURL($abs=null){
//if canonical url enabled always return absolute
if(is_null($abs)) $abs = $conf['canonical'];
- if($conf['basedir']){
+ if(!empty($conf['basedir'])){
$dir = $conf['basedir'];
}elseif(substr($_SERVER['SCRIPT_NAME'],-4) == '.php'){
$dir = dirname($_SERVER['SCRIPT_NAME']);
@@ -456,7 +456,7 @@ function getBaseURL($abs=null){
if(!$abs) return $dir;
//use config option if available, trim any slash from end of baseurl to avoid multiple consecutive slashes in the path
- if($conf['baseurl']) return rtrim($conf['baseurl'],'/').$dir;
+ if(!empty($conf['baseurl'])) return rtrim($conf['baseurl'],'/').$dir;
//split hostheader into host and port
if(isset($_SERVER['HTTP_HOST'])){