summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2018-02-07 16:49:07 +0100
committerAndrey Andreev <narf@devilix.net>2018-02-07 16:49:07 +0100
commit43538863b7bdd52529c38ad314ffc0f9edbbaa8b (patch)
tree675ec1d3cbfeb3915e882e2775d9e0905c096273
parente88ae153c30f534a1cce525e9365fe7ef05b22f7 (diff)
[ci skip] Finalize changes from PR #5394
-rw-r--r--system/helpers/download_helper.php25
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 16 insertions, 10 deletions
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 43e12cf9e..b7a5336b6 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -147,21 +147,26 @@ if ( ! function_exists('force_download'))
@ob_clean();
}
- $disposition = 'attachment; filename="'.$filename.'";';
- $charset = config_item('charset');
- if (strtoupper($charset) !== 'UTF-8')
+ // RFC 6266 allows for multibyte filenames, but only in UTF-8,
+ // so we have to make it conditional ...
+ $utf8_filename = $filename;
+ $charset = strtoupper(config_item('charset'));
+ if ($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);
- }
+ $utf8_filename = (UTF8_ENABLED === TRUE)
+ ? get_instance()->utf8->convert_to_utf8($filename, $charset)
+ : FALSE;
+ }
+ else
+ {
+ $utf8_filename = $filename;
}
+ isset($utf8_filename[0]) && $utf8_filename = " filename*=UTF-8''".rawurlencode($utf8_filename);
+
// Generate the server headers
header('Content-Type: '.$mime);
- header('Content-Disposition: '.$disposition);
+ header('Content-Disposition: attachment; filename="'.$filename.'";'.$utf8_filename);
header('Expires: 0');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.$filesize);
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 37c276f19..92403bc25 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -94,6 +94,7 @@ Release Date: Not Released
- Updated :php:func:`force_download()` to allow existing files to be renamed for download.
- Updated :php:func:`force_download()` to better utilize available server memory.
+ - Updated :php:func:`force_download()` to serve multibyte filenames when possible, via the ``filename*`` attribute specified by IETF `RFC 6266 <https://tools.ietf.org/html/rfc6266>`_.
- :doc:`String Helper <helpers/string_helper>` changes include: