博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HTTP下载文件名称编码说明
阅读量:7199 次
发布时间:2019-06-29

本文共 1685 字,大约阅读时间需要 5 分钟。

HTTP下载保存文件名

下载文件需要保存的名称 在响应报文头中 Content-Disposition 响应报文头域中指定, 例如
Content-Disposition: attachment; filename*="utf8''%E4%B8%AD%E6%96%87%20%E6%96%87%E4%BB%B6%E5%90%8D.txt"

其中filename后指定文件名称。

HTTP规范要求

  http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html

content-disposition = "Content-Disposition" ":"                              disposition-type *( ";" disposition-parm )        disposition-type = "attachment" | disp-extension-token        disposition-parm = filename-parm | disp-extension-parm        filename-parm = "filename" "=" quoted-string        disp-extension-token = token        disp-extension-parm = token "=" ( token | quoted-string )

An example is

Content-Disposition: attachment; filename="fname.ext"

 

参考 http://haoyu.farbox.com/post/download-header
http://www.phpv.net/html/1675.html
http://blog.angryfox.com/?tag=%E4%B8%8B%E8%BD%BD
 

兼容性规则

各个浏览器实现的规则又和HTTP规范有些小差异。

给出转码规则代码:

-- 获取文件名local filename = cgilua.QUERY.IF_FILENAMEUTF8local encfilename = cgilua.urlcode.escape(filename)encfilename = string.gsub (encfilename, "+", "%%20") -- tested '中文文 件名.txt' local useragent = sapi.Request.servervariable"HTTP_USER_AGENT"local contentdispositionif useragent then    if string.match( useragent, "MSIE" )        -- IE11 伪装成 mozilla, 需要借助Trident关键字区分        or string.match( useragent, "Trident" ) then        contentdisposition = 'attachment; filename="' .. encfilename .. '"'    elseif string.match( useragent, "/Firefox/" ) then        contentdisposition = "attachment; filename*=\"UTF-8''"..encfilename.."\""    else        contentdisposition = 'attachment; filename="' .. filename .. '"'    endelse    contentdisposition = 'attachment; filename="' .. filename .. '"'end

 

转载地址:http://cddum.baihongyu.com/

你可能感兴趣的文章
HashSet、LinkedHashSet、TreeSet的区别
查看>>
linux下搭建Ipsec+L2TP ×××服务
查看>>
搭建NFS文件共享--实例解析
查看>>
Unity3D教程:扫描全盘获取文件路径
查看>>
Windows 8 消费者预览版体验
查看>>
linux 运行级别和chkconfig的用法
查看>>
python写的部署windows下zabbix客户端脚本
查看>>
cisco 查找ARP及防范
查看>>
使用开源KgCMS新闻系统建站时的JAVA云主机选型
查看>>
Java调用带有输入参数为Blob类型的存储过程
查看>>
rar
查看>>
/proc/sys/net/ipv4 详解1
查看>>
List集合去除重复元素,不打乱顺序(数组转List)
查看>>
vs code 使用 typings 对nodejs 代码进行提示
查看>>
我的友情链接
查看>>
没想到我也有了博客
查看>>
交换机以太通道的配置
查看>>
yum.conf配置详解
查看>>
Yii2的log分析
查看>>
再次过了软考网工
查看>>