From 826b6196b748c2c1ccca0dbb5703fd50c600afa5 Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Fri, 30 Sep 2016 21:34:44 +0300 Subject: - download helper uses better file buffering when the content of a local file is output'd --- system/helpers/download_helper.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a6463dfd7..7f5c2397a 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -121,11 +121,6 @@ if ( ! function_exists('force_download')) $filename = implode('.', $x); } - if ($data === NULL && ($fp = @fopen($filepath, 'rb')) === FALSE) - { - return; - } - // Clean output buffer if (ob_get_level() !== 0 && @ob_end_clean() === FALSE) { @@ -146,13 +141,12 @@ if ( ! function_exists('force_download')) exit($data); } - // Flush 1MB chunks of data - while ( ! feof($fp) && ($data = fread($fp, 1048576)) !== FALSE) + // Flush the file + if (@readfile($filepath) === FALSE) { - echo $data; + return; } - fclose($fp); exit; } } -- cgit v1.2.3-24-g4f1b From c867754cbb2260efeaa25ff9c339989807e8c713 Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Mon, 31 Oct 2016 01:38:18 +0200 Subject: download helper should be able to offer a download by reading a local file and also a custom destination filename. --- system/helpers/download_helper.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a6463dfd7..289ea199a 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -56,7 +56,7 @@ if ( ! function_exists('force_download')) * * Generates headers that force a download to happen * - * @param string filename + * @param mixed filename (or an array of local file path => destination filename) * @param mixed the data to be downloaded * @param bool whether to try and send the actual file MIME type * @return void @@ -69,14 +69,28 @@ if ( ! function_exists('force_download')) } elseif ($data === NULL) { - if ( ! @is_file($filename) OR ($filesize = @filesize($filename)) === FALSE) + // Is $filename an array as ['local source path' => 'destination filename']? + if(is_array($filename)) { - return; - } + $filepath = key($filename); + $filename = current($filename); - $filepath = $filename; - $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename)); - $filename = end($filename); + if ( ! @is_file($filepath) OR ($filesize = @filesize($filepath)) === FALSE) + { + return; + } + } + else + { + if ( ! @is_file($filename) OR ($filesize = @filesize($filename)) === FALSE) + { + return; + } + + $filepath = $filename; + $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename)); + $filename = end($filename); + } } else { -- cgit v1.2.3-24-g4f1b From 214a537e4df19f3885943604c1b8a49c3f64993d Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Mon, 31 Oct 2016 01:42:41 +0200 Subject: single entry restriction if $filename is an array --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 289ea199a..a1d149f91 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,7 +70,7 @@ if ( ! function_exists('force_download')) elseif ($data === NULL) { // Is $filename an array as ['local source path' => 'destination filename']? - if(is_array($filename)) + if(is_array($filename) && count($filename) === 1) { $filepath = key($filename); $filename = current($filename); -- cgit v1.2.3-24-g4f1b From c953c128649e06bb1a3594e56459cf14bdb6e048 Mon Sep 17 00:00:00 2001 From: George PETCULESCU Date: Mon, 31 Oct 2016 14:06:48 +0200 Subject: fixed coding style --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a1d149f91..32ee773bb 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,7 +70,7 @@ if ( ! function_exists('force_download')) elseif ($data === NULL) { // Is $filename an array as ['local source path' => 'destination filename']? - if(is_array($filename) && count($filename) === 1) + if(is_array($filename) && count($filename)) { $filepath = key($filename); $filename = current($filename); -- cgit v1.2.3-24-g4f1b From b907c8ad41dfb4a9394b3a73182f0abf7fe14f94 Mon Sep 17 00:00:00 2001 From: George PETCULESCU Date: Mon, 31 Oct 2016 14:08:36 +0200 Subject: fixed coding style (2) --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 32ee773bb..9158272ef 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,7 +70,7 @@ if ( ! function_exists('force_download')) elseif ($data === NULL) { // Is $filename an array as ['local source path' => 'destination filename']? - if(is_array($filename) && count($filename)) + if(is_array($filename) && count($filename) == 1) { $filepath = key($filename); $filename = current($filename); -- cgit v1.2.3-24-g4f1b From 627b050e89ea3e9794e7ad03c28aeb770417357a Mon Sep 17 00:00:00 2001 From: George Petculescu Date: Tue, 1 Nov 2016 08:16:47 +0200 Subject: if download helper receives a numeric array now it won't work --- system/helpers/download_helper.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 9158272ef..4bab69005 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -75,6 +75,11 @@ if ( ! function_exists('force_download')) $filepath = key($filename); $filename = current($filename); + if(is_int($filepath)) + { + return; + } + if ( ! @is_file($filepath) OR ($filesize = @filesize($filepath)) === FALSE) { return; -- cgit v1.2.3-24-g4f1b From 54a1138a864a9d2d3ce7ef6d4b9d22df86440bb5 Mon Sep 17 00:00:00 2001 From: gxgpet Date: Tue, 1 Nov 2016 10:44:32 +0200 Subject: Fixed coding style (this time for real) --- system/helpers/download_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 4bab69005..eb714c1ff 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,12 +70,12 @@ if ( ! function_exists('force_download')) elseif ($data === NULL) { // Is $filename an array as ['local source path' => 'destination filename']? - if(is_array($filename) && count($filename) == 1) + if (is_array($filename) && count($filename) == 1) { $filepath = key($filename); $filename = current($filename); - if(is_int($filepath)) + if (is_int($filepath)) { return; } -- cgit v1.2.3-24-g4f1b From 3e86cc27d531e15c7d7dc7c606f87e1694272f92 Mon Sep 17 00:00:00 2001 From: George PETCULESCU Date: Tue, 1 Nov 2016 14:02:46 +0200 Subject: fixed when $filename is an array with a different count than 1. --- system/helpers/download_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index eb714c1ff..43c3924a3 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -70,8 +70,13 @@ if ( ! function_exists('force_download')) elseif ($data === NULL) { // Is $filename an array as ['local source path' => 'destination filename']? - if (is_array($filename) && count($filename) == 1) + if (is_array($filename)) { + if (count($filename) != 1) + { + return; + } + $filepath = key($filename); $filename = current($filename); -- cgit v1.2.3-24-g4f1b From 49407be71a80d67151a296be25fff2468c68ab55 Mon Sep 17 00:00:00 2001 From: George PETCULESCU Date: Tue, 1 Nov 2016 16:10:59 +0200 Subject: strict comparison of 1. --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 43c3924a3..9619c61b1 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -72,7 +72,7 @@ if ( ! function_exists('force_download')) // Is $filename an array as ['local source path' => 'destination filename']? if (is_array($filename)) { - if (count($filename) != 1) + if (count($filename) !== 1) { return; } -- cgit v1.2.3-24-g4f1b From fced25f5728ce81fe810216fcaa4ccec7523f6c9 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Sat, 31 Dec 2016 08:46:18 -0800 Subject: Update copyright data to 2017 --- system/helpers/download_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 9619c61b1..b9a0e6be9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2016, British Columbia Institute of Technology + * Copyright (c) 2014 - 2017, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2016, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From b27e4451ee2ae65581f3245971155927c75d6ec7 Mon Sep 17 00:00:00 2001 From: Zach Ploskey Date: Mon, 13 Feb 2017 16:21:37 -0800 Subject: Don't duplicate is_file and filesize checks Move duplicate is_file and file_size checks out of if/else branches. Signed-off-by: Zach Ploskey --- system/helpers/download_helper.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index ea3da1bf4..7500bc827 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -84,23 +84,18 @@ if ( ! function_exists('force_download')) { return; } - - if ( ! @is_file($filepath) OR ($filesize = @filesize($filepath)) === FALSE) - { - return; - } } else { - if ( ! @is_file($filename) OR ($filesize = @filesize($filename)) === FALSE) - { - return; - } - $filepath = $filename; $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename)); $filename = end($filename); } + + if ( ! @is_file($filepath) OR ($filesize = @filesize($filepath)) === FALSE) + { + return; + } } else { -- cgit v1.2.3-24-g4f1b From 0b9d5c35e46eff9e8d19f66047eff88067bdcf4a Mon Sep 17 00:00:00 2001 From: vlakoff Date: Wed, 15 Feb 2017 19:17:20 +0100 Subject: Do not fail if the array pointer is after the element --- system/helpers/download_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 7500bc827..b2f0edb48 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -77,6 +77,7 @@ if ( ! function_exists('force_download')) return; } + reset($filename); $filepath = key($filename); $filename = current($filename); -- cgit v1.2.3-24-g4f1b From 208381009ed12768478b2e8110bfb6e506acc3e1 Mon Sep 17 00:00:00 2001 From: Master Yoda Date: Tue, 9 Jan 2018 00:53:27 -0800 Subject: Annual copyright update --- system/helpers/download_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index b2f0edb48..02d4ce11e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2017, British Columbia Institute of Technology + * Copyright (c) 2014 - 2018, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/) + * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) * @license http://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 719e4acbafecbef3f143affb45a8dcd90945dd04 Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Tue, 30 Jan 2018 01:43:48 +0900 Subject: fix rfc6266 --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 02d4ce11e..338725477 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -149,7 +149,7 @@ if ( ! function_exists('force_download')) // Generate the server headers header('Content-Type: '.$mime); - header('Content-Disposition: attachment; filename="'.$filename.'"'); + header('Content-Disposition: attachment; filename="'.$filename.'"; filename*=UTF-8\'\''.rawurlencode($filename)); header('Expires: 0'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.$filesize); -- cgit v1.2.3-24-g4f1b 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/helpers/download_helper.php') 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 From c755a6b0b32b58c86989e5c6cfd8085732b1e497 Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Thu, 1 Feb 2018 11:50:36 +0900 Subject: refactor use Utf8 class --- system/helpers/download_helper.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 93d468421..a169c3fd5 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -151,13 +151,10 @@ if ( ! function_exists('force_download')) $encoding = config_item('charset'); if (strtoupper($encoding) !== 'UTF-8') { - if (MB_ENABLED) + $CI =& get_instance(); + if ($converted_filename = $CI->utf8->convert_to_utf8($utf8_filename, $encoding) ) { - $utf8_filename = mb_convert_encoding($utf8_filename, 'UTF-8', $encoding); - } - elseif (ICONV_ENABLED) - { - $utf8_filename = @iconv($encoding, 'UTF-8', $utf8_filename); + $utf8_filename = $converted_filename; } } -- cgit v1.2.3-24-g4f1b From a70cdc5a9ed9e181e9f76fdc94006f3cc20198cd Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Mon, 5 Feb 2018 22:44:56 +0900 Subject: change use direct convert_to_utf8 method --- system/helpers/download_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a169c3fd5..fdca76830 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -151,8 +151,8 @@ if ( ! function_exists('force_download')) $encoding = config_item('charset'); if (strtoupper($encoding) !== 'UTF-8') { - $CI =& get_instance(); - if ($converted_filename = $CI->utf8->convert_to_utf8($utf8_filename, $encoding) ) + $converted_filename = get_instance()->utf8->convert_to_utf8($utf8_filename, $encoding); + if ($converted_filename) { $utf8_filename = $converted_filename; } -- cgit v1.2.3-24-g4f1b From e5d719d822646a7c0bcd1a2732eb8fe19357444a Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Mon, 5 Feb 2018 23:04:17 +0900 Subject: Determine exactly whether converted filename is false --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index fdca76830..344fd4e9a 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -152,7 +152,7 @@ if ( ! function_exists('force_download')) if (strtoupper($encoding) !== 'UTF-8') { $converted_filename = get_instance()->utf8->convert_to_utf8($utf8_filename, $encoding); - if ($converted_filename) + if ($converted_filename !== FALSE) { $utf8_filename = $converted_filename; } -- cgit v1.2.3-24-g4f1b From 4dc34279cdc19b7a1df3385b1f679aeac6767c89 Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Mon, 5 Feb 2018 23:05:50 +0900 Subject: change variable name --- system/helpers/download_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 344fd4e9a..afdb77956 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -148,10 +148,10 @@ if ( ! function_exists('force_download')) } $utf8_filename = $filename; - $encoding = config_item('charset'); - if (strtoupper($encoding) !== 'UTF-8') + $charset = config_item('charset'); + if (strtoupper($charset) !== 'UTF-8') { - $converted_filename = get_instance()->utf8->convert_to_utf8($utf8_filename, $encoding); + $converted_filename = get_instance()->utf8->convert_to_utf8($utf8_filename, $charset); if ($converted_filename !== FALSE) { $utf8_filename = $converted_filename; -- cgit v1.2.3-24-g4f1b From 8f04f20b0f63ace705e4371a24d0ddf139655dba Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Tue, 6 Feb 2018 00:01:45 +0900 Subject: Changed to include Content-Disposition parameters in variables --- system/helpers/download_helper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index afdb77956..43e12cf9e 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -147,21 +147,21 @@ if ( ! function_exists('force_download')) @ob_clean(); } - $utf8_filename = $filename; + $disposition = 'attachment; filename="'.$filename.'";'; $charset = config_item('charset'); if (strtoupper($charset) !== 'UTF-8') { - $converted_filename = get_instance()->utf8->convert_to_utf8($utf8_filename, $charset); - if ($converted_filename !== FALSE) + // charset attribute (RFC 6266 only allows UTF-8) + $utf8_filename = get_instance()->utf8->convert_to_utf8($filename, $charset); + if ($utf8_filename !== FALSE) { - $utf8_filename = $converted_filename; + $disposition .= ' filename*=UTF-8\'\''.rawurlencode($utf8_filename); } } // Generate the server headers header('Content-Type: '.$mime); - // charset attribute (RFC 6266 only allows UTF-8) - header('Content-Disposition: attachment; filename="'.$filename.'"; filename*=UTF-8\'\''.rawurlencode($utf8_filename)); + header('Content-Disposition: '.$disposition); header('Expires: 0'); header('Content-Transfer-Encoding: binary'); header('Content-Length: '.$filesize); -- cgit v1.2.3-24-g4f1b From 43538863b7bdd52529c38ad314ffc0f9edbbaa8b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 7 Feb 2018 17:49:07 +0200 Subject: [ci skip] Finalize changes from PR #5394 --- system/helpers/download_helper.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'system/helpers/download_helper.php') 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); -- cgit v1.2.3-24-g4f1b From ff1029018a8e5ba7261cdfb71fb3d102c3efc22b Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Thu, 8 Feb 2018 22:08:23 +0900 Subject: Fixed bug that character code did not change --- system/helpers/download_helper.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index b7a5336b6..a2e28a6e9 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -153,9 +153,7 @@ if ( ! function_exists('force_download')) $charset = strtoupper(config_item('charset')); if ($charset !== 'UTF-8') { - $utf8_filename = (UTF8_ENABLED === TRUE) - ? get_instance()->utf8->convert_to_utf8($filename, $charset) - : FALSE; + $utf8_filename = get_instance()->utf8->convert_to_utf8($filename, $charset); } else { -- cgit v1.2.3-24-g4f1b From c82f3236069fae1f21a0900b026d346752d089c9 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 12 Feb 2018 14:31:20 +0200 Subject: [ci skip] More polish on the download helper --- system/helpers/download_helper.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a2e28a6e9..000e4c707 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -149,17 +149,10 @@ if ( ! function_exists('force_download')) // 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') - { - $utf8_filename = get_instance()->utf8->convert_to_utf8($filename, $charset); - } - else - { - $utf8_filename = $filename; - } - + $utf8_filename = ($charset !== 'UTF-8') + ? $utf8_filename = get_instance()->utf8->convert_to_utf8($filename, $charset) + : $filename; isset($utf8_filename[0]) && $utf8_filename = " filename*=UTF-8''".rawurlencode($utf8_filename); // Generate the server headers -- cgit v1.2.3-24-g4f1b From b7ca09f989ae344682395d16402bcf07062dd655 Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Wed, 14 Feb 2018 16:32:41 +0900 Subject: Delete unnecessary assignment expressions --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 000e4c707..901e3277c 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -151,7 +151,7 @@ if ( ! function_exists('force_download')) // so we have to make it conditional ... $charset = strtoupper(config_item('charset')); $utf8_filename = ($charset !== 'UTF-8') - ? $utf8_filename = get_instance()->utf8->convert_to_utf8($filename, $charset) + ? get_instance()->utf8->convert_to_utf8($filename, $charset) : $filename; isset($utf8_filename[0]) && $utf8_filename = " filename*=UTF-8''".rawurlencode($utf8_filename); -- cgit v1.2.3-24-g4f1b From 52a87e506d4fc70bd5922b07a532852d28f28ab6 Mon Sep 17 00:00:00 2001 From: Mehdi Bounya Date: Thu, 17 May 2018 23:41:30 +0000 Subject: http:// to https:// --- system/helpers/download_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 901e3277c..b1a1b0232 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -29,8 +29,8 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) - * @license http://opensource.org/licenses/MIT MIT License + * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (https://bcit.ca/) + * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 * @filesource -- cgit v1.2.3-24-g4f1b From 8bb638e392f5991c05ec9a1e57b882213844dc6f Mon Sep 17 00:00:00 2001 From: Jim Parry Date: Wed, 26 Dec 2018 21:03:09 -0800 Subject: Update copyright date to 2019 --- system/helpers/download_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index b1a1b0232..4d7829640 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -6,7 +6,7 @@ * * This content is released under the MIT License (MIT) * - * Copyright (c) 2014 - 2018, British Columbia Institute of Technology + * Copyright (c) 2014 - 2019, British Columbia Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,7 +29,7 @@ * @package CodeIgniter * @author EllisLab Dev Team * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) - * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (https://bcit.ca/) + * @copyright Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/) * @license https://opensource.org/licenses/MIT MIT License * @link https://codeigniter.com * @since Version 1.0.0 -- cgit v1.2.3-24-g4f1b From 6ba0207160f8f2b99c79dd285bccf45f574ec660 Mon Sep 17 00:00:00 2001 From: sapics Date: Wed, 24 Jun 2020 11:51:36 +0900 Subject: Fix user guide url Replace from https://codeigniter.com/user_guide/* to https://codeigniter.com/userguide3/* --- system/helpers/download_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/download_helper.php') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 4d7829640..9bdeea13d 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -44,7 +44,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); * @subpackage Helpers * @category Helpers * @author EllisLab Dev Team - * @link https://codeigniter.com/user_guide/helpers/download_helper.html + * @link https://codeigniter.com/userguide3/helpers/download_helper.html */ // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b