diff options
author | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
---|---|---|
committer | Derek Jones <derek.jones@ellislab.com> | 2008-01-28 22:00:20 +0100 |
commit | 269b942a2bf7b022795e591d9b0ad04526ee7e09 (patch) | |
tree | f465bb5a700d4cc5d72ca6e55e251640a46b869b /system/helpers/download_helper.php | |
parent | a25530f6594c7ba45b3faa9537fda9f807069759 (diff) |
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.
Diffstat (limited to 'system/helpers/download_helper.php')
-rw-r--r-- | system/helpers/download_helper.php | 94 |
1 files changed, 48 insertions, 46 deletions
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 |