如何解决跨浏览器PHP下载文件名中的中文乱码问题
小编给大家分享一下如何解决跨浏览器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下载文件名中的中文乱码问题”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!