$ _FILE [“ file”] [“ name”]中的相对路径被截断为基名?

他们

我想将文件发布到服务器中,文件Content-Disposition头中提供了一个相对路径,该路径提供了文件的文件名(在带有curl 7.47的Ubuntu上使用PHP 7.0):

curl server/index.php -F "[email protected];filename=a/b/c.txt"

应用该--trace-ascii /dev/stdout选项显示:

0000: POST /index.php HTTP/1.1
0031: Host: server
004a: User-Agent: curl/7.47.0
0063: Accept: */*
0070: Content-Length: 111511
0088: Expect: 100-continue
009e: Content-Type: multipart/form-data; boundary=--------------------
00de: ----e656f77ee2b4759a
00f4: 
...
0000: --------------------------e656f77ee2b4759a
002c: Content-Disposition: form-data; name="file"; filename="a/b/c.txt
006c: "
006f: Content-Type: application/octet-stream
0097: 
...

现在,我的简单测试脚本<?php print_r($_FILES["file"]); ?>输出:

Array
(
    [name] => c.txt
    [type] => application/octet-stream
    [tmp_name] => /tmp/phpNaikad
    [error] => 0
    [size] => 111310
)

但是,我期望[name] => a/b/c.txt我的逻辑缺陷在哪里?

根据https://stackoverflow.com/a/3393822/1647737,文件名可以包含相对路径。

PHP手册也意味着这并建议用消毒basename()

巫师

正如我们从php-解释器源中看到的那样_basename()出于安全原因和/或为了修复某些特定浏览器的缺点而调用了filter。

档案:php-src / main / rfc1867.c

〜1151行及以下:

        /* The \ check should technically be needed for win32 systems only where
         * it is a valid path separator. However, IE in all it's wisdom always sends
         * the full path of the file on the user's filesystem, which means that unless
         * the user does basename() they get a bogus file name. Until IE's user base drops
         * to nill or problem is fixed this code must remain enabled for all systems. */
        s = _basename(internal_encoding, filename);
        if (!s) {
            s = filename;
        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

file.getPath() 的相对路径

使用File.separator的相对路径

带有相对路径的file_get_contents

file_exists相对路径不起作用

__FILE__和PDB的相对路径

相对路径INSIDE file_get_contents结果

Java如何解析新File()中的相对路径?

将位于相对路径中的文件转换为 Django File 对象

使用gulp-file-include从HTML模板到文件的相对路径

如何在File类中提供相对路径以上传任何文件?

pySpark 本地模式 - 使用 file:/// 与相对路径加载文本文件

如何在Orchard和System.IO.File方法中使用(根)相对路径?

Webpack [url / file-loader]无法解析URL的相对路径

image.fromfile() 不能使用相对路径“~/folder/file”

File_exists函数不适用于通过symlink目录的相对路径

当file_path是相对路径时,os.path.isfile(file_path)返回false,为什么?

如何从Java项目中的相对路径读取文件?java.io.File找不到指定的路径

为什么File.OpenRead()将相对路径附加到可执行文件?

java.nio.file.WatchEvent仅提供相对路径。如何获取修改后的文件的绝对路径?

在postgres中设置trigger_file的路径名

为什么“awk ... file | tee file”会截断文件?

在相对路径中迭代多个文件名

在Visual Studio中为SFML设置相对路径

如何读取 Future<File> 路径?

为什么不建议将硬编码的绝对路径名传递给File对象构造函数File(String)

从URL路径中删除file:///前缀

jar清单中的绝对路径名和相对路径名

Android FileInputStream将路径从file:///更改为/ file:/

当参数是绝对路径名时,File :: Basename :: dirname是否总是返回父目录或根目录吗?