diff options
author | Andrey Andreev <narf@devilix.net> | 2016-11-01 15:12:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-01 15:12:34 +0100 |
commit | c6737d2110fd9c9ccc79c5407c5ae3e11b24422d (patch) | |
tree | 8fc462d871a9922853a63cbb9ba9206a16b34554 /system/helpers | |
parent | 52d264d960aded1620ae8505e2935de12b0209e9 (diff) | |
parent | 49407be71a80d67151a296be25fff2468c68ab55 (diff) |
Merge pull request #4891 from gxgpet/develop_31102016
Allow existing file rename-for-download in force_download() helper
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/download_helper.php | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a6463dfd7..9619c61b1 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,38 @@ 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; + if (count($filename) !== 1) + { + return; + } + + $filepath = key($filename); + $filename = current($filename); + + if (is_int($filepath)) + { + 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); } - - $filepath = $filename; - $filename = explode('/', str_replace(DIRECTORY_SEPARATOR, '/', $filename)); - $filename = end($filename); } else { |