summaryrefslogtreecommitdiffstats
path: root/system/helpers/download_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers/download_helper.php')
-rw-r--r--system/helpers/download_helper.php94
1 files changed, 48 insertions, 46 deletions
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index e8bc2f7f6..2d0e737c9 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -37,60 +37,62 @@
* @param mixed the data to be downloaded
* @return void
*/
-function force_download($filename = '', $data = '')
+if (! function_exists('force_download'))
{
- if ($filename == '' OR $data == '')
+ function force_download($filename = '', $data = '')
{
- return FALSE;
- }
+ if ($filename == '' OR $data == '')
+ {
+ return FALSE;
+ }
- // Try to determine if the filename includes a file extension.
- // We need it in order to set the MIME type
- if (FALSE === strpos($filename, '.'))
- {
- return FALSE;
- }
+ // Try to determine if the filename includes a file extension.
+ // We need it in order to set the MIME type
+ if (FALSE === strpos($filename, '.'))
+ {
+ return FALSE;
+ }
- // Grab the file extension
- $x = explode('.', $filename);
- $extension = end($x);
+ // Grab the file extension
+ $x = explode('.', $filename);
+ $extension = end($x);
- // Load the mime types
- @include(APPPATH.'config/mimes'.EXT);
+ // Load the mime types
+ @include(APPPATH.'config/mimes'.EXT);
- // Set a default mime if we can't find it
- if ( ! isset($mimes[$extension]))
- {
- $mime = 'application/octet-stream';
- }
- else
- {
- $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
- }
+ // Set a default mime if we can't find it
+ if ( ! isset($mimes[$extension]))
+ {
+ $mime = 'application/octet-stream';
+ }
+ else
+ {
+ $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
+ }
- // Generate the server headers
- if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
- {
- header('Content-Type: "'.$mime.'"');
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header("Content-Transfer-Encoding: binary");
- header('Pragma: public');
- header("Content-Length: ".strlen($data));
- }
- else
- {
- header('Content-Type: "'.$mime.'"');
- header('Content-Disposition: attachment; filename="'.$filename.'"');
- header("Content-Transfer-Encoding: binary");
- header('Expires: 0');
- header('Pragma: no-cache');
- header("Content-Length: ".strlen($data));
- }
+ // Generate the server headers
+ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
+ {
+ header('Content-Type: "'.$mime.'"');
+ header('Content-Disposition: attachment; filename="'.$filename.'"');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
+ header("Content-Transfer-Encoding: binary");
+ header('Pragma: public');
+ header("Content-Length: ".strlen($data));
+ }
+ else
+ {
+ header('Content-Type: "'.$mime.'"');
+ header('Content-Disposition: attachment; filename="'.$filename.'"');
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ header("Content-Length: ".strlen($data));
+ }
- echo $data;
+ echo $data;
+ }
}
-
?> \ No newline at end of file