download_helper.php
Go to the documentation of this file.00001 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 if ( ! function_exists('force_download'))
00041 {
00042 function force_download($filename = '', $data = '')
00043 {
00044 if ($filename == '' OR $data == '')
00045 {
00046 return FALSE;
00047 }
00048
00049
00050
00051 if (FALSE === strpos($filename, '.'))
00052 {
00053 return FALSE;
00054 }
00055
00056
00057 $x = explode('.', $filename);
00058 $extension = end($x);
00059
00060
00061 @include(APPPATH.'config/mimes'.EXT);
00062
00063
00064 if ( ! isset($mimes[$extension]))
00065 {
00066 $mime = 'application/octet-stream';
00067 }
00068 else
00069 {
00070 $mime = (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
00071 }
00072
00073
00074 if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
00075 {
00076 header('Content-Type: "'.$mime.'"');
00077 header('Content-Disposition: attachment; filename="'.$filename.'"');
00078 header('Expires: 0');
00079 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
00080 header("Content-Transfer-Encoding: binary");
00081 header('Pragma: public');
00082 header("Content-Length: ".strlen($data));
00083 }
00084 else
00085 {
00086 header('Content-Type: "'.$mime.'"');
00087 header('Content-Disposition: attachment; filename="'.$filename.'"');
00088 header("Content-Transfer-Encoding: binary");
00089 header('Expires: 0');
00090 header('Pragma: no-cache');
00091 header("Content-Length: ".strlen($data));
00092 }
00093
00094 exit($data);
00095 }
00096 }
00097
00098
00099
00100