diff options
author | Andrey Andreev <narf@bofh.bg> | 2012-03-20 14:48:00 +0100 |
---|---|---|
committer | Andrey Andreev <narf@bofh.bg> | 2012-03-20 14:48:00 +0100 |
commit | 31cf46eaec3b4613d5b46f9caed8bdd346b581cc (patch) | |
tree | 047b9d74def6254639b3d9b2833f36336dc99f8a /system/helpers/download_helper.php | |
parent | b68e70b2cd81f83fd038ca2c2d00fde210a8ee0e (diff) | |
parent | 733921ecc4da80f08a9d50ff0fb05bccf23de09d (diff) |
Merge upstream branch
Diffstat (limited to 'system/helpers/download_helper.php')
-rw-r--r-- | system/helpers/download_helper.php | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index a8c59c2c0..96ff29dec 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -2,7 +2,7 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * @@ -60,19 +60,19 @@ if ( ! function_exists('force_download')) // Set the default MIME type to send $mime = 'application/octet-stream'; + $x = explode('.', $filename); + $extension = end($x); + if ($set_mime === TRUE) { - /* If we're going to detect the MIME type, - * we'll need a file extension. - */ - if (FALSE === strpos($filename, '.')) + if (count($x) === 1 OR $extension === '') { + /* If we're going to detect the MIME type, + * we'll need a file extension. + */ return FALSE; } - $extension = explode('.', $filename); - $extension = end($extension); - // Load the mime types if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/mimes.php')) { @@ -90,8 +90,20 @@ if ( ! function_exists('force_download')) } } + /* It was reported that browsers on Android 2.1 (and possibly older as well) + * need to have the filename extension upper-cased in order to be able to + * download it. + * + * Reference: http://digiblog.de/2011/04/19/android-and-the-download-file-headers/ + */ + if (count($x) !== 1 && isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/Android\s(1|2\.[01])/', $_SERVER['HTTP_USER_AGENT'])) + { + $x[count($x) - 1] = strtoupper($extension); + $filename = implode('.', $x); + } + // Generate the server headers - header('Content-Type: "'.$mime.'"'); + header('Content-Type: '.$mime); header('Content-Disposition: attachment; filename="'.$filename.'"'); header('Expires: 0'); header('Content-Transfer-Encoding: binary'); |