summaryrefslogtreecommitdiffstats
path: root/system/helpers/download_helper.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xssn.at>2010-02-06 23:14:56 +0100
committerFlorian Pritz <bluewind@xssn.at>2010-02-06 23:31:27 +0100
commit9e9d77b4072de4f8c73e8bbade07a8f27734e4bd (patch)
treea5d709254968fed8f3acdb9eec68fde2faa14b94 /system/helpers/download_helper.php
Initial commit
Signed-off-by: Florian Pritz <bluewind@xssn.at>
Diffstat (limited to 'system/helpers/download_helper.php')
-rw-r--r--system/helpers/download_helper.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php
new file mode 100644
index 000000000..a8f7b1a7f
--- /dev/null
+++ b/system/helpers/download_helper.php
@@ -0,0 +1,100 @@
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package CodeIgniter
+ * @author ExpressionEngine Dev Team
+ * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
+ * @license http://codeigniter.com/user_guide/license.html
+ * @link http://codeigniter.com
+ * @since Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * CodeIgniter Download Helpers
+ *
+ * @package CodeIgniter
+ * @subpackage Helpers
+ * @category Helpers
+ * @author ExpressionEngine Dev Team
+ * @link http://codeigniter.com/user_guide/helpers/download_helper.html
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Force Download
+ *
+ * Generates headers that force a download to happen
+ *
+ * @access public
+ * @param string filename
+ * @param mixed the data to be downloaded
+ * @return void
+ */
+if ( ! function_exists('force_download'))
+{
+ function force_download($filename = '', $data = '')
+ {
+ 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;
+ }
+
+ // Grab the file extension
+ $x = explode('.', $filename);
+ $extension = end($x);
+
+ // 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];
+ }
+
+ // 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));
+ }
+
+ exit($data);
+ }
+}
+
+
+/* End of file download_helper.php */
+/* Location: ./system/helpers/download_helper.php */ \ No newline at end of file