From 269b942a2bf7b022795e591d9b0ad04526ee7e09 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 28 Jan 2008 21:00:20 +0000 Subject: added ability to "extend" helpers * modified Loader to check for prefixed helpers in application/helpers folder * surrounded provided helper functions with if (! function_exists('foo')) conditionals so the user's helper functions take precedent. --- system/helpers/download_helper.php | 94 +++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 46 deletions(-) (limited to 'system/helpers/download_helper.php') 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 -- cgit v1.2.3-24-g4f1b