PHP用header强制下载时IE文件名中文乱码问题解决方法


PHP #header #文件下载2014-04-09 23:19
解决方案如下:

<?php
$filename = "一个网在线教程.txt";
$ua = $_SERVER["HTTP_USER_AGENT"];
$encoded_filename = urlencode($filename);
$encoded_filename = str_replace("+", "%20", $encoded_filename);
header('Content-Type: application/octet-stream');
if (preg_match("/MSIE/", $ua)) {
    header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
} else if (preg_match("/Firefox/", $ua)) {
    header('Content-Disposition: attachment; filename*="utf8''' . $filename . '"');
} else {
    header('Content-Disposition: attachment; filename="' . $filename . '"');
}


相关文章

粤ICP备11097351号-1