Skip to content

Commit d764f1d

Browse files
bjoern-tantauBjörn Tantau
and
Björn Tantau
authored
Fix #77372: Retain full path of files for directory uploads (#6917)
To fix https://bugs.php.net/bug.php?id=77372 and improve support of `<input type="file" name="files" multiple webkitdirectory>` I introduced another item to the `$_FILES` array called `full_path`, containing the full filename, as supplied by the user-agent. Co-authored-by: Björn Tantau <bjoern@bjoern-tantau.de>
1 parent 21422e8 commit d764f1d

26 files changed

+238
-49
lines changed

ext/session/tests/rfc1867.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ string(%d) "rfc1867"
5454
bool(true)
5555
array(2) {
5656
["file1"]=>
57-
array(5) {
57+
array(6) {
5858
["name"]=>
5959
string(9) "file1.txt"
60+
["full_path"]=>
61+
string(9) "file1.txt"
6062
["type"]=>
6163
string(0) ""
6264
["tmp_name"]=>
@@ -67,9 +69,11 @@ array(2) {
6769
int(1)
6870
}
6971
["file2"]=>
70-
array(5) {
72+
array(6) {
7173
["name"]=>
7274
string(9) "file2.txt"
75+
["full_path"]=>
76+
string(9) "file2.txt"
7377
["type"]=>
7478
string(0) ""
7579
["tmp_name"]=>

ext/session/tests/rfc1867_cleanup.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ string(%d) "rfc1867-cleanup"
5454
bool(true)
5555
array(2) {
5656
["file1"]=>
57-
array(5) {
57+
array(6) {
5858
["name"]=>
5959
string(9) "file1.txt"
60+
["full_path"]=>
61+
string(9) "file1.txt"
6062
["type"]=>
6163
string(0) ""
6264
["tmp_name"]=>
@@ -67,9 +69,11 @@ array(2) {
6769
int(1)
6870
}
6971
["file2"]=>
70-
array(5) {
72+
array(6) {
7173
["name"]=>
7274
string(9) "file2.txt"
75+
["full_path"]=>
76+
string(9) "file2.txt"
7377
["type"]=>
7478
string(0) ""
7579
["tmp_name"]=>

ext/session/tests/rfc1867_disabled.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ session_destroy();
4747
string(%d) "rfc1867-disabled"
4848
array(2) {
4949
["file1"]=>
50-
array(5) {
50+
array(6) {
5151
["name"]=>
5252
string(9) "file1.txt"
53+
["full_path"]=>
54+
string(9) "file1.txt"
5355
["type"]=>
5456
string(0) ""
5557
["tmp_name"]=>
@@ -60,9 +62,11 @@ array(2) {
6062
int(1)
6163
}
6264
["file2"]=>
63-
array(5) {
65+
array(6) {
6466
["name"]=>
6567
string(9) "file2.txt"
68+
["full_path"]=>
69+
string(9) "file2.txt"
6670
["type"]=>
6771
string(0) ""
6872
["tmp_name"]=>

ext/session/tests/rfc1867_disabled_2.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ session_destroy();
4747
string(%d) "rfc1867-disabled-2"
4848
array(2) {
4949
["file1"]=>
50-
array(5) {
50+
array(6) {
5151
["name"]=>
5252
string(9) "file1.txt"
53+
["full_path"]=>
54+
string(9) "file1.txt"
5355
["type"]=>
5456
string(0) ""
5557
["tmp_name"]=>
@@ -60,9 +62,11 @@ array(2) {
6062
int(1)
6163
}
6264
["file2"]=>
63-
array(5) {
65+
array(6) {
6466
["name"]=>
6567
string(9) "file2.txt"
68+
["full_path"]=>
69+
string(9) "file2.txt"
6670
["type"]=>
6771
string(0) ""
6872
["tmp_name"]=>

ext/session/tests/rfc1867_inter.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ session_destroy();
5757
string(%d) "rfc1867-inter"
5858
array(2) {
5959
["file1"]=>
60-
array(5) {
60+
array(6) {
6161
["name"]=>
6262
string(9) "file1.txt"
63+
["full_path"]=>
64+
string(9) "file1.txt"
6365
["type"]=>
6466
string(0) ""
6567
["tmp_name"]=>
@@ -70,9 +72,11 @@ array(2) {
7072
int(1)
7173
}
7274
["file2"]=>
73-
array(5) {
75+
array(6) {
7476
["name"]=>
7577
string(9) "file2.txt"
78+
["full_path"]=>
79+
string(9) "file2.txt"
7680
["type"]=>
7781
string(0) ""
7882
["tmp_name"]=>

ext/session/tests/rfc1867_no_name.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ session_destroy();
4747
string(%d) "rfc1867-no-name"
4848
array(2) {
4949
["file1"]=>
50-
array(5) {
50+
array(6) {
5151
["name"]=>
5252
string(9) "file1.txt"
53+
["full_path"]=>
54+
string(9) "file1.txt"
5355
["type"]=>
5456
string(0) ""
5557
["tmp_name"]=>
@@ -60,9 +62,11 @@ array(2) {
6062
int(1)
6163
}
6264
["file2"]=>
63-
array(5) {
65+
array(6) {
6466
["name"]=>
6567
string(9) "file2.txt"
68+
["full_path"]=>
69+
string(9) "file2.txt"
6670
["type"]=>
6771
string(0) ""
6872
["tmp_name"]=>

ext/session/tests/rfc1867_sid_cookie.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ string(%d) "rfc1867-sid-cookie"
5353
bool(true)
5454
array(2) {
5555
["file1"]=>
56-
array(5) {
56+
array(6) {
5757
["name"]=>
5858
string(9) "file1.txt"
59+
["full_path"]=>
60+
string(9) "file1.txt"
5961
["type"]=>
6062
string(0) ""
6163
["tmp_name"]=>
@@ -66,9 +68,11 @@ array(2) {
6668
int(1)
6769
}
6870
["file2"]=>
69-
array(5) {
71+
array(6) {
7072
["name"]=>
7173
string(9) "file2.txt"
74+
["full_path"]=>
75+
string(9) "file2.txt"
7276
["type"]=>
7377
string(0) ""
7478
["tmp_name"]=>

ext/session/tests/rfc1867_sid_get.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ string(%d) "rfc1867-sid-get"
5151
bool(true)
5252
array(2) {
5353
["file1"]=>
54-
array(5) {
54+
array(6) {
5555
["name"]=>
5656
string(9) "file1.txt"
57+
["full_path"]=>
58+
string(9) "file1.txt"
5759
["type"]=>
5860
string(0) ""
5961
["tmp_name"]=>
@@ -64,9 +66,11 @@ array(2) {
6466
int(1)
6567
}
6668
["file2"]=>
67-
array(5) {
69+
array(6) {
6870
["name"]=>
6971
string(9) "file2.txt"
72+
["full_path"]=>
73+
string(9) "file2.txt"
7074
["type"]=>
7175
string(0) ""
7276
["tmp_name"]=>

ext/session/tests/rfc1867_sid_get_2.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ string(%d) "rfc1867-sid-get-2"
5353
bool(true)
5454
array(2) {
5555
["file1"]=>
56-
array(5) {
56+
array(6) {
5757
["name"]=>
5858
string(9) "file1.txt"
59+
["full_path"]=>
60+
string(9) "file1.txt"
5961
["type"]=>
6062
string(0) ""
6163
["tmp_name"]=>
@@ -66,9 +68,11 @@ array(2) {
6668
int(1)
6769
}
6870
["file2"]=>
69-
array(5) {
71+
array(6) {
7072
["name"]=>
7173
string(9) "file2.txt"
74+
["full_path"]=>
75+
string(9) "file2.txt"
7276
["type"]=>
7377
string(0) ""
7478
["tmp_name"]=>

ext/session/tests/rfc1867_sid_invalid.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ string(%d) ""
6565
bool(true)
6666
array(2) {
6767
["file1"]=>
68-
array(5) {
68+
array(6) {
6969
["name"]=>
7070
string(9) "file1.txt"
71+
["full_path"]=>
72+
string(9) "file1.txt"
7173
["type"]=>
7274
string(0) ""
7375
["tmp_name"]=>
@@ -78,9 +80,11 @@ array(2) {
7880
int(1)
7981
}
8082
["file2"]=>
81-
array(5) {
83+
array(6) {
8284
["name"]=>
8385
string(9) "file2.txt"
86+
["full_path"]=>
87+
string(9) "file2.txt"
8488
["type"]=>
8589
string(0) ""
8690
["tmp_name"]=>

ext/session/tests/rfc1867_sid_only_cookie.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ string(%d) "rfc1867-sid-only-cookie"
5353
bool(true)
5454
array(2) {
5555
["file1"]=>
56-
array(5) {
56+
array(6) {
5757
["name"]=>
5858
string(9) "file1.txt"
59+
["full_path"]=>
60+
string(9) "file1.txt"
5961
["type"]=>
6062
string(0) ""
6163
["tmp_name"]=>
@@ -66,9 +68,11 @@ array(2) {
6668
int(1)
6769
}
6870
["file2"]=>
69-
array(5) {
71+
array(6) {
7072
["name"]=>
7173
string(9) "file2.txt"
74+
["full_path"]=>
75+
string(9) "file2.txt"
7276
["type"]=>
7377
string(0) ""
7478
["tmp_name"]=>

ext/session/tests/rfc1867_sid_only_cookie_2.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ string(%d) "%s"
5050
bool(true)
5151
array(2) {
5252
["file1"]=>
53-
array(5) {
53+
array(6) {
5454
["name"]=>
5555
string(9) "file1.txt"
56+
["full_path"]=>
57+
string(9) "file1.txt"
5658
["type"]=>
5759
string(0) ""
5860
["tmp_name"]=>
@@ -63,9 +65,11 @@ array(2) {
6365
int(1)
6466
}
6567
["file2"]=>
66-
array(5) {
68+
array(6) {
6769
["name"]=>
6870
string(9) "file2.txt"
71+
["full_path"]=>
72+
string(9) "file2.txt"
6973
["type"]=>
7074
string(0) ""
7175
["tmp_name"]=>

ext/session/tests/rfc1867_sid_post.phpt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ string(%d) "rfc1867-sid-post"
4949
bool(true)
5050
array(2) {
5151
["file1"]=>
52-
array(5) {
52+
array(6) {
5353
["name"]=>
5454
string(9) "file1.txt"
55+
["full_path"]=>
56+
string(9) "file1.txt"
5557
["type"]=>
5658
string(0) ""
5759
["tmp_name"]=>
@@ -62,9 +64,11 @@ array(2) {
6264
int(1)
6365
}
6466
["file2"]=>
65-
array(5) {
67+
array(6) {
6668
["name"]=>
6769
string(9) "file2.txt"
70+
["full_path"]=>
71+
string(9) "file2.txt"
6872
["type"]=>
6973
string(0) ""
7074
["tmp_name"]=>

main/rfc1867.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ PHPAPI int (*php_rfc1867_callback)(unsigned int event, void *event_data, void **
5555
static void safe_php_register_variable(char *var, char *strval, size_t val_len, zval *track_vars_array, bool override_protection);
5656

5757
/* The longest property name we use in an uploaded file array */
58-
#define MAX_SIZE_OF_INDEX sizeof("[tmp_name]")
58+
#define MAX_SIZE_OF_INDEX sizeof("[full_path]")
5959

6060
/* The longest anonymous name */
6161
#define MAX_SIZE_ANONNAME 33
@@ -1142,9 +1142,20 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
11421142
snprintf(lbuf, llen, "%s[name]", param);
11431143
}
11441144
register_http_post_files_variable(lbuf, s, &PG(http_globals)[TRACK_VARS_FILES], 0);
1145-
efree(filename);
11461145
s = NULL;
11471146

1147+
/* Add full path of supplied file for folder uploads via
1148+
* <input type="file" name="files" multiple webkitdirectory>
1149+
*/
1150+
/* Add $foo[full_path] */
1151+
if (is_arr_upload) {
1152+
snprintf(lbuf, llen, "%s[full_path][%s]", abuf, array_index);
1153+
} else {
1154+
snprintf(lbuf, llen, "%s[full_path]", param);
1155+
}
1156+
register_http_post_files_variable(lbuf, filename, &PG(http_globals)[TRACK_VARS_FILES], 0);
1157+
efree(filename);
1158+
11481159
/* Possible Content-Type: */
11491160
if (cancel_upload || !(cd = php_mime_get_hdr_value(header, "Content-Type"))) {
11501161
cd = "";

sapi/cli/tests/php_cli_server_005.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ Content-type: text/html; charset=UTF-8
5252

5353
array(1) {
5454
["userfile"]=>
55-
array(5) {
55+
array(6) {
5656
["name"]=>
5757
string(12) "laruence.txt"
58+
["full_path"]=>
59+
string(12) "laruence.txt"
5860
["type"]=>
5961
string(10) "text/plain"
6062
["tmp_name"]=>

tests/basic/021.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ var_dump($_POST);
2424
--EXPECTF--
2525
array(1) {
2626
["pics"]=>
27-
array(5) {
27+
array(6) {
2828
["name"]=>
2929
string(12) "bug37276.txt"
30+
["full_path"]=>
31+
string(12) "bug37276.txt"
3032
["type"]=>
3133
string(10) "text/plain"
3234
["tmp_name"]=>

0 commit comments

Comments
 (0)