Php $U文件[“文件”][“名称”中的相对路径是否被截断为basename?

Php $U文件[“文件”][“名称”中的相对路径是否被截断为basename?,php,curl,file-upload,path,Php,Curl,File Upload,Path,我想在内容配置标题中向服务器发布一个文件,并提供文件名的相对路径(在带有curl 7.47的Ubuntu上使用PHP7.0): 应用--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

我想在
内容配置
标题中向服务器发布一个文件,并提供文件名的相对路径(在带有curl 7.47的Ubuntu上使用PHP7.0):

应用
--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: 
...
现在,我的简单测试脚本
输出:

Array
(
    [name] => c.txt
    [type] => application/octet-stream
    [tmp_name] => /tmp/phpNaikad
    [error] => 0
    [size] => 111310
)
然而,我期望
[name]=>a/b/c.txt
。我的逻辑缺陷在哪里

根据文件名可以包含相对路径

和建议使用
basename()

进行清理,我们可以从出于安全原因调用的
\u basename()
过滤器中看到,和/或修复某些特定浏览器的缺点

文件:phpsrc/main/rfc1867.c

第1151行及以下:


我认为由于安全原因,您无法获取上传文件的原始路径。php和javascript都无法检索此信息。@向导您可以在浏览器中进行上载;除了旧的IE版本,没有浏览器发送完整的本地路径。但是在这里,截断必须发生在服务器端(从包含完整路径的跟踪中可以看到)。。但我怀疑php方面出于同样的原因切断了这个连接。你可以@Wizard谢谢你的参考,我会看的。如果PHP确实是罪魁祸首,那么随着时间的推移,这种行为可能已经改变,因为手册和其他来源仍然建议使用basename()清理(?)编辑:只需阅读源代码-无法相信该参数是旧的IE,并且评论提到将在将来删除此行为…@Wizard您想将您的评论作为答案发布,以便我可以接受吗?如果没有,我会在稍后写一个关于你的评论的答案。感谢您在PHP解释器源代码中指向该确切位置的指针!
Array
(
    [name] => c.txt
    [type] => application/octet-stream
    [tmp_name] => /tmp/phpNaikad
    [error] => 0
    [size] => 111310
)
        /* 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;
        }