我知道我们应该替换正斜杠,例如分解路径并使用数组的最后一个元素作为文件名。
但是为什么使用时正斜杠会转换为连字符/破折号
header('Content-Disposition: attachment; filename="'.$local_file.'"');
当$local_file
类似于/file
下载的文件的文件名为-file
此行为是否在某处描述过?
rfc 论文没有提到这一点,是吗? http://www.faqs.org/rfcs/rfc2183.html
最佳答案
这是特定于客户的。大多数浏览器只会删除任何路径/
前缀。但对正斜杠进行转码也同样合理。
RFC2616 中提到了这一点,http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html ,第 19.5.1 节
The receiving user agent SHOULD NOT respect any directory path information present in the filename-parm parameter, which is the only parameter believed to apply to HTTP implementations at this time. The filename SHOULD be treated as a terminal component only.
Network Working Group, R. Fielding et al, (c) The Internet Society (1999)
理由当然是,出于安全原因,不应将 HTTP 有效负载提取到任何预定义路径。
关于php - 为什么正斜杠转换为连字符/破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27215225/