From a3e36019c787eb87fd0bc2e5ba9948c85c4a2c44 Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Thu, 1 Feb 2018 11:38:00 +0900 Subject: change filename. convert to utf-8 --- system/helpers/download_helper.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 338725477..93d468421 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -147,9 +147,24 @@ if ( ! function_exists('force_download')) @ob_clean(); } + $utf8_filename = $filename; + $encoding = config_item('charset'); + if (strtoupper($encoding) !== 'UTF-8') + { + if (MB_ENABLED) + { + $utf8_filename = mb_convert_encoding($utf8_filename, 'UTF-8', $encoding); + } + elseif (ICONV_ENABLED) + { + $utf8_filename = @iconv($encoding, 'UTF-8', $utf8_filename); + } + } + // Generate the server headers header('Content-Type: '.$mime); - header('Content-Disposition: attachment; filename="'.$filename.'"; filename*=UTF-8\'\''.rawurlencode($filename)); + // charset attribute (RFC 6266 only allows UTF-8) + header('Content-Disposition: attachment; filename="'.$filename.'"; filename*=UTF-8\'\''.rawurlencode($utf8_filename)); header('Expires: 0'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.$filesize); -- cgit v1.2.3-24-g4f1b