php header函数下载中文文件名乱码(ie/chrome)

header函数在php中用处很多,下面我来介绍利用php中的header函数下载文件是中文在不同浏览器筹码的解决办法.

在下载文件中加入下段代码即可解决,代码如下:

  1. $name = rawurlencode($filename);
  2. header("Content-type: text/plain; charset=utf-8");
  3. header("Content-Type: application/force-download");
  4. header("Content-Type: application/octet-stream");
  5. header("Content-Type: application/download");
  6. header('Content-Disposition:inline;filename="'.$name.txt.'"');
  7. header("Content-Transfer-Encoding: binary");
  8. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  9. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  10. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  11. header("Pragma: no-cache");