Skip to content

Instantly share code, notes, and snippets.

@homleen
Created August 8, 2013 03:50
Show Gist options
  • Save homleen/6181302 to your computer and use it in GitHub Desktop.
Save homleen/6181302 to your computer and use it in GitHub Desktop.
PHP下载文件名乱码不完全解决方案。
<?php
$ua = $_SERVER['HTTP_USER_AGENT'];
$name = "+ 孙_燕-姿 &✺☞& 繁體字&2013.doc";
header('Content-Type: application/octet-stream');
if (preg_match("/MSIE/", $ua)) {
header('Content-Disposition: attachment; filename="' . rawurlencode($name) . '"');
} else if (preg_match("/Firefox/", $ua)) {
header('Content-Disposition: attachment; filename*="utf8\'\'' . rawurlencode($name) . '"');
} else {
header('Content-Disposition: attachment; filename="' . $name . '"');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment