php - 为什么正斜杠转换为连字符/破折号

标签 php filenames slash content-disposition

我知道我们应该替换正斜杠,例如分解路径并使用数组的最后一个元素作为文件名。

但是为什么使用时正斜杠会转换为连字符/破折号

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/

相关文章:

php - 序列化和反序列化时防止对象重写

php - 这个简单的 PHP 函数包装器看起来是否适合其用途?

php - Docker容器中的Symfony环境

c++ - 获取不带扩展名的文件名?

python - os.path.join(p1,p2) 省略 p1 的斜杠

php - 如何在 url 中的第二个斜杠后获取字符串-使用 php?

php - 在 Codeigniter 中使用多个规则集

linux - 通过 bash 更改特定文件夹中的文件名

php - 从 PHP 脚本中获取 HTML 文件的名称

php - 如何在 php 中回显斜杠?