Thursday, January 28, 2016

PHP 解決 IE 下載中文檔名亂碼

最近在測試檔案下載,輸出中文檔名的時候。
發現IE 會變成亂碼,後來從保哥的文章找到了解決方法。

URL_ENCODE() 來解決中文亂碼問題。
For Example
$file_name=urlencode($file_name);
header("Content-Type:text/html; charset=utf-8");
header('Last-Modified: '.gmdate('D, d M Y H:i:s',time()).' GMT');
header('Pragma: no-cache');
header('Content-Encoding: none');
header('Content-Disposition: '.'attachment'.'; filename='.$file_name);
header('Content-type: '.$file_type);
header('Content-Length: '.filesize( $file_path_on_server ));
?>


Reference
ASP.NET 如何設定強制下載檔案並正確處理中文檔名的問題

No comments:

Post a Comment