欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

跨浏览器PHP下载文件名中的中文乱码问题解决方法,

程序员文章站 2022-06-12 13:50:54
...

跨浏览器PHP下载文件名中的中文乱码问题解决方法,

本文实例讲述了跨浏览器PHP下载文件名中的中文乱码问题解决方法。分享给大家供大家参考。具体如下:

复制代码 代码如下: $ua = $_SERVER["HTTP_USER_AGENT"];
$filename = "中文 文件名.txt";
$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 . '"');
}
print 'ABC';
?>

希望本文所述对大家的php程序设计有所帮助。