From b6eb95349e6e339c90f8165bcd0471bd6268f8c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 17 Dec 2012 16:23:12 +0100 Subject: [PATCH] fix utf8 filenames in ie download response header according to rfc5987, see http://stackoverflow.com/questions/93551/how-to-encode-the-filename-parameter-of-content-disposition-header-in-http --- apps/files/download.php | 7 ++++++- lib/files.php | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/files/download.php b/apps/files/download.php index 6475afb56e..e2149cd413 100644 --- a/apps/files/download.php +++ b/apps/files/download.php @@ -40,7 +40,12 @@ if(!OC_Filesystem::file_exists($filename)) { $ftype=OC_Filesystem::getMimeType( $filename ); header('Content-Type:'.$ftype); -header('Content-Disposition: attachment; filename="'.basename($filename).'"'); +if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { + header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); +} else { + header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) + . '; filename="' . rawurlencode( basename($filename) ) . '"' ); +} OCP\Response::disableCaching(); header('Content-Length: '.OC_Filesystem::filesize($filename)); diff --git a/lib/files.php b/lib/files.php index 152ed8f34a..f8bae778ed 100644 --- a/lib/files.php +++ b/lib/files.php @@ -197,7 +197,12 @@ class OC_Files { } OC_Util::obEnd(); if($zip or OC_Filesystem::is_readable($filename)) { - header('Content-Disposition: attachment; filename="'.basename($filename).'"'); + if ( preg_match( "/MSIE/", $_SERVER["HTTP_USER_AGENT"] ) ) { + header( 'Content-Disposition: attachment; filename="' . rawurlencode( basename($filename) ) . '"' ); + } else { + header( 'Content-Disposition: attachment; filename*=UTF-8\'\'' . rawurlencode( basename($filename) ) + . '; filename="' . rawurlencode( basename($filename) ) . '"' ); + } header('Content-Transfer-Encoding: binary'); OC_Response::disableCaching(); if($zip) {