I want to post a file to a server with a relative path supplied to the file's filename within the Content-Disposition
header (using PHP 7.0 on Ubuntu with curl 7.47):
curl server/index.php -F "file=@somefile.txt;filename=a/b/c.txt"
Applying the --trace-ascii /dev/stdout
option shows:
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:
...
Now, my simple test script <?php print_r($_FILES["file"]); ?>
outputs:
Array
(
[name] => c.txt
[type] => application/octet-stream
[tmp_name] => /tmp/phpNaikad
[error] => 0
[size] => 111310
)
However, I expected [name] => a/b/c.txt
. Where is the flaw in my logic?
According to https://stackoverflow.com/a/3393822/1647737 the filename can contain relative path.
The PHP manual also implies this and suggests sanitizing with basename()
.