1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
5 * An open source application development framework for PHP 4.3.2 or newer
8 * @author ExpressionEngine Dev Team
9 * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc.
10 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
16 // ------------------------------------------------------------------------
19 * CodeIgniter Download Helpers
21 * @package CodeIgniter
24 * @author ExpressionEngine Dev Team
25 * @link http://codeigniter.com/user_guide/helpers/download_helper.html
28 // ------------------------------------------------------------------------
33 * Generates headers that force a download to happen
36 * @param string filename
37 * @param mixed the data to be downloaded
40 if ( ! function_exists('force_download'))
42 function force_download($filename = '', $data = '')
44 if ($filename == '' OR $data == '')
49 // Try to determine if the filename includes a file extension.
50 // We need it in order to set the MIME type
51 if (FALSE === strpos($filename, '.'))
56 // Grab the file extension
57 $x = explode('.', $filename);
60 // Load the mime types
61 @include(APPPATH.'config/mimes'.EXT);
63 // Set a default mime if we can't find it
64 if ( ! isset($mimes[$extension]))
66 $mime = 'application/octet-stream';
70 $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
73 // Generate the server headers
74 if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
76 header('Content-Type: "'.$mime.'"');
77 header('Content-Disposition: attachment; filename="'.$filename.'"');
79 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
80 header("Content-Transfer-Encoding: binary");
81 header('Pragma: public');
82 header("Content-Length: ".strlen($data));
86 header('Content-Type: "'.$mime.'"');
87 header('Content-Disposition: attachment; filename="'.$filename.'"');
88 header("Content-Transfer-Encoding: binary");
90 header('Pragma: no-cache');
91 header("Content-Length: ".strlen($data));
99 /* End of file download_helper.php */
100 /* Location: ./system/helpers/download_helper.php */