summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2018-02-07 16:28:55 +0100
committerGitHub <noreply@github.com>2018-02-07 16:28:55 +0100
commite88ae153c30f534a1cce525e9365fe7ef05b22f7 (patch)
tree1cdb94630f337c13d8ebfc6e0017270261d794ad
parentb37902586b10bdbd7a34480950098800ddf4b120 (diff)
parent8f04f20b0f63ace705e4371a24d0ddf139655dba (diff)
[ci skip] Merge pull request #5394 from ytetsuro/fix/rfc6266
Give force_download a header conforming to RFC 6266
-rw-r--r--system/helpers/download_helper.php14
1 files changed, 13 insertions, 1 deletions
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 02d4ce11e..43e12cf9e 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -147,9 +147,21 @@ if ( ! function_exists('force_download'))
@ob_clean();
}
+ $disposition = 'attachment; filename="'.$filename.'";';
+ $charset = config_item('charset');
+ if (strtoupper($charset) !== 'UTF-8')
+ {
+ // charset attribute (RFC 6266 only allows UTF-8)
+ $utf8_filename = get_instance()->utf8->convert_to_utf8($filename, $charset);
+ if ($utf8_filename !== FALSE)
+ {
+ $disposition .= ' filename*=UTF-8\'\''.rawurlencode($utf8_filename);
+ }
+ }
+
// Generate the server headers
header('Content-Type: '.$mime);
- header('Content-Disposition: attachment; filename="'.$filename.'"');
+ header('Content-Disposition: '.$disposition);
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.$filesize);