标签:
其中filename后指定文件名称。
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规范有些小差异。
给出转码规则代码:
-- 获取文件名 local filename = cgilua.QUERY.IF_FILENAMEUTF8 local encfilename = cgilua.urlcode.escape(filename) encfilename = string.gsub (encfilename, "+", "%%20") -- tested ‘中文文 件名.txt‘
local useragent = sapi.Request.servervariable"HTTP_USER_AGENT" local contentdisposition if 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 .. ‘"‘ end else contentdisposition = ‘attachment; filename="‘ .. filename .. ‘"‘ end
标签:
原文地址:http://www.cnblogs.com/lightsong/p/4567823.html