Skip to content

Commit

Permalink
Merge branch 'develop' of git://github.com/EllisLab/CodeIgniter into …
Browse files Browse the repository at this point in the history
…session
  • Loading branch information
chrisguiney committed Mar 11, 2012
2 parents b7272fa + 3d933b6 commit a41def1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions system/helpers/download_helper.php
Expand Up @@ -60,19 +60,19 @@ function force_download($filename = '', $data = '', $set_mime = FALSE)
// 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'))
{
Expand All @@ -90,6 +90,18 @@ function force_download($filename = '', $data = '', $set_mime = FALSE)
}
}

/* 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-Disposition: attachment; filename="'.$filename.'"');
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelog.rst
Expand Up @@ -43,6 +43,7 @@ Release Date: Not Released
- Changed humanize to include a second param for the separator.
- Refactored ``plural()`` and ``singular()`` to avoid double pluralization and support more words.
- Added an optional third parameter to ``force_download()`` that enables/disables sending the actual file MIME type in the Content-Type header (disabled by default).
- Added a work-around in force_download() for a bug Android <= 2.1, where the filename extension needs to be in uppercase.

- Database

Expand Down

0 comments on commit a41def1

Please sign in to comment.