summaryrefslogtreecommitdiffstats
path: root/system/helpers/download_helper.php
diff options
context:
space:
mode:
authorGeorge Petculescu <gxgpet@gmail.com>2016-10-31 00:38:18 +0100
committerGeorge Petculescu <gxgpet@gmail.com>2016-10-31 00:38:18 +0100
commitc867754cbb2260efeaa25ff9c339989807e8c713 (patch)
treeec9246db1c7366237c96771cde0173659fcd0b23 /system/helpers/download_helper.php
parent67b40a561111a5a65faa245cd4c575e8d945cfb8 (diff)
download helper should be able to offer a download by reading a local file and also a custom destination filename.
Diffstat (limited to 'system/helpers/download_helper.php')
-rw-r--r--system/helpers/download_helper.php28
1 files changed, 21 insertions, 7 deletions
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
{