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.php49
1 files changed, 23 insertions, 26 deletions
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
index 19192a147..8fe66e222 100644
--- a/system/helpers/download_helper.php
+++ b/system/helpers/download_helper.php
@@ -1,4 +1,4 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
/**
* CodeIgniter
*
@@ -24,6 +24,7 @@
* @since Version 1.0
* @filesource
*/
+defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Download Helpers
@@ -37,21 +38,21 @@
// ------------------------------------------------------------------------
-/**
- * Force Download
- *
- * Generates headers that force a download to happen
- *
- * @param string filename
- * @param mixed the data to be downloaded
- * @param bool wether to try and send the actual file MIME type
- * @return void
- */
if ( ! function_exists('force_download'))
{
+ /**
+ * Force Download
+ *
+ * Generates headers that force a download to happen
+ *
+ * @param string filename
+ * @param mixed the data to be downloaded
+ * @param bool whether to try and send the actual file MIME type
+ * @return void
+ */
function force_download($filename = '', $data = '', $set_mime = FALSE)
{
- if ($filename == '' OR $data == '')
+ if ($filename === '' OR $data === '')
{
return FALSE;
}
@@ -73,14 +74,7 @@ if ( ! function_exists('force_download'))
}
// Load the mime types
- if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
- {
- include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php');
- }
- elseif (is_file(APPPATH.'config/mimes.php'))
- {
- include(APPPATH.'config/mimes.php');
- }
+ $mimes =& get_mimes();
// Only change the default MIME if we can find one
if (isset($mimes[$extension]))
@@ -101,6 +95,12 @@ if ( ! function_exists('force_download'))
$filename = implode('.', $x);
}
+ // Clean output buffer
+ if (ob_get_level() !== 0)
+ {
+ ob_clean();
+ }
+
// Generate the server headers
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.$filename.'"');
@@ -111,14 +111,11 @@ if ( ! function_exists('force_download'))
// Internet Explorer-specific headers
if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
- }
- else
- {
- header('Pragma: no-cache');
+ header('Cache-Control: no-cache, no-store, must-revalidate');
}
+ header('Pragma: no-cache');
+
exit($data);
}
}