admin管理员组

文章数量:1545268

浏览器能正确识别的编码格式,只要按照这样的编码来设置对应的Content-Disposition,那么应该就不会出现中文文件名的乱码问题了。
首先,文件名作为参数保存Content-Disposition里也就是header头里,content-type指定的是响应文件在浏览器显示的编码,header头里的编码没法指定,浏览器不同,Content-Disposition值可以有以下几种编码格式 。

  1. 直接urlencode:

    Content-Disposition: attachment; filename="%e7%be%8e%e5%a5%bd%e5%ae%b6.chm"

  2. Base64编码:

    Content-Disposition: attachment; filename="=?UTF8?B?c3RydXRzMi4w5Lit5paH5pWZ56iLLmNobQ==?="

  3. RFC2231规定的标准:

    Content-Disposition: attachment; filename*=UTF-8’’%E5%9B%9E%E6%89%A7.msg

  4. 直接ISO编码的文件名:

    Content-Disposition: attachment;filename=“测试.txt”

然后,各浏览器支持的对应编码格式为:

  1. IE浏览器,采用URLEncoder编码
  2. Opera浏览器,采用filename*方式
  3. Safari浏览器,采用ISO编码的中文输出
  4. Chrome浏览器,采用Base64编码或ISO编码的中文输出
  5. FireFox浏览器,采用Base64或filename*或ISO编码的中文输出

直接在下载链接的header头中加入

本文标签: 乱码中文浏览器名字文件