diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2014-01-07 11:06:20 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2014-01-07 11:06:20 -0800 |
commit | 2d5427efa99e910abe46f2c6ab567b2392169f26 (patch) | |
tree | cf34ecdace87f8a4d015eaa8920ba89c6bd7394c /lib | |
parent | f2fbfbc665b90dbd23c0a353b07fad7c67176a6a (diff) | |
parent | 09bd5bd517fee80e8b44b7645b51a8ba482a4d7c (diff) | |
download | nextcloud-server-2d5427efa99e910abe46f2c6ab567b2392169f26.tar.gz nextcloud-server-2d5427efa99e910abe46f2c6ab567b2392169f26.zip |
Merge pull request #6290 from owncloud/files-androidcontentdisposition
Files androidcontentdisposition
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files.php | 7 | ||||
-rwxr-xr-x | lib/private/request.php | 23 | ||||
-rw-r--r-- | lib/private/response.php | 14 | ||||
-rw-r--r-- | lib/public/response.php | 9 |
4 files changed, 47 insertions, 6 deletions
diff --git a/lib/private/files.php b/lib/private/files.php index 6ffa14c0d91..e6c81d58bd2 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -115,12 +115,7 @@ class OC_Files { } OC_Util::obEnd(); if ($zip or \OC\Files\Filesystem::isReadable($filename)) { - if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { - header( 'Content-Disposition: attachment; filename="' . rawurlencode($name) . '"' ); - } else { - header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode($name) - . '; filename="' . rawurlencode($name) . '"' ); - } + OC_Response::setContentDispositionHeader($name, 'attachment'); header('Content-Transfer-Encoding: binary'); OC_Response::disableCaching(); if ($zip) { diff --git a/lib/private/request.php b/lib/private/request.php index b2afda35922..d9d5ae08e28 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -7,6 +7,11 @@ */ class OC_Request { + + const USER_AGENT_IE = '/MSIE/'; + // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent + const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; + /** * @brief Check overwrite condition * @param string $type @@ -210,4 +215,22 @@ class OC_Request { return false; } } + + /** + * Checks whether the user agent matches a given regex + * @param string|array $agent agent name or array of agent names + * @return boolean true if at least one of the given agent matches, + * false otherwise + */ + static public function isUserAgent($agent) { + if (!is_array($agent)) { + $agent = array($agent); + } + foreach ($agent as $regex) { + if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) { + return true; + } + } + return false; + } } diff --git a/lib/private/response.php b/lib/private/response.php index 674176d078b..04746437347 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -148,6 +148,20 @@ class OC_Response { } /** + * Sets the content disposition header (with possible workarounds) + * @param string $filename file name + * @param string $type disposition type, either 'attachment' or 'inline' + */ + static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { + if (OC_Request::isUserAgent(array(OC_Request::USER_AGENT_IE, OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME))) { + header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' ); + } else { + header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename ) + . '; filename="' . rawurlencode( $filename ) . '"' ); + } + } + + /** * @brief Send file as response, checking and setting caching headers * @param $filepath of file to send */ diff --git a/lib/public/response.php b/lib/public/response.php index 2ca0a0c9fa4..24d3c81d628 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -55,6 +55,15 @@ class Response { } /** + * Sets the content disposition header (with possible workarounds) + * @param string $filename file name + * @param string $type disposition type, either 'attachment' or 'inline' + */ + static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { + \OC_Response::setContentDispositionHeader( $filename, $type ); + } + + /** * Disable browser caching * @see enableCaching with cache_time = 0 */ |