From 533c07f9f26e25249589e73c523b932f33d39b96 Mon Sep 17 00:00:00 2001 From: Lynn Chen Date: Thu, 8 Aug 2013 12:33:46 +0800 Subject: [PATCH] filename should be encoded --- libraries/csv.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/csv.php b/libraries/csv.php index 23baccc..19e73de 100644 --- a/libraries/csv.php +++ b/libraries/csv.php @@ -255,10 +255,22 @@ public function to_file($path) */ public function to_download($name) { + $ua = $_SERVER['HTTP_USER_AGENT']; + + if (preg_match("/MSIE/", $ua)) { + $cd = 'attachment; filename="' . rawurlencode($name) . '"'; + + } else if (preg_match("/Firefox/", $ua)) { + $cd = 'attachment; filename*="utf8\'\'' . rawurlencode($name) . '"'; + + } else { + $cd = 'attachment; filename="' . $name . '"'; + } + // response return Response::make($this->to_string(), 200, array( 'content-type' => 'application/octet-stream', - 'content-disposition' => 'attachment; filename="'.$name.'"', + 'content-disposition' => $cd, )); }