>  기사  >  백엔드 개발  >  php跨浏览器下载文件时中文乱码问题的解决方法

php跨浏览器下载文件时中文乱码问题的解决方法

WBOY
WBOY원래의
2016-07-25 08:58:531140검색
  1. /**

  2. * 解决跨浏览器下载文件,中文乱码的问题
  3. * edit bbs.it-home.org
  4. */
  5. $ua = $_SERVER["HTTP_USER_AGENT"];
  6. $filename = "中文 文件名.txt";

  7. $encoded_filename = urlencode($filename);
  8. $encoded_filename = str_replace("+", "%20", $encoded_filename);
  9. header('Content-Type: application/octet-stream');

  10. if (preg_match("/MSIE/", $ua)) {

  11. header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
  12. } else if (preg_match("/Firefox/", $ua)) {
  13. header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"');
  14. } else {
  15. header('Content-Disposition: attachment; filename="' . $filename . '"');
  16. }
  17. print 'ABC';

  18. ?>
复制代码


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.