Skip to content

Commit 099b423

Browse files
Retain full path of files for directory uploads
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 `fullpath`, containing the full filename, as supplied by the user-agent.
1 parent c276c16 commit 099b423

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

main/rfc1867.c

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,9 +1149,39 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler) /* {{{ */
11491149
snprintf(lbuf, llen, "%s[name]", param);
11501150
}
11511151
register_http_post_files_variable(lbuf, s, &PG(http_globals)[TRACK_VARS_FILES], 0);
1152-
efree(filename);
11531152
s = NULL;
11541153

1154+
/* Add $foo_fullpath */
1155+
if (llen < strlen(param) + MAX_SIZE_OF_INDEX + 1) {
1156+
llen = (int)strlen(param);
1157+
lbuf = (char *) safe_erealloc(lbuf, llen, 1, MAX_SIZE_OF_INDEX + 1);
1158+
llen += MAX_SIZE_OF_INDEX + 1;
1159+
}
1160+
1161+
if (is_arr_upload) {
1162+
if (abuf) efree(abuf);
1163+
abuf = estrndup(param, strlen(param)-array_len);
1164+
snprintf(lbuf, llen, "%s_fullpath[%s]", abuf, array_index);
1165+
} else {
1166+
snprintf(lbuf, llen, "%s_fullpath", param);
1167+
}
1168+
1169+
/* Add full path of supplied file for folder uploads via
1170+
* <input type="file" name="files" multiple webkitdirectory>
1171+
*/
1172+
if (!is_anonymous) {
1173+
safe_php_register_variable(lbuf, filename, strlen(filename), NULL, 0);
1174+
}
1175+
1176+
/* Add $foo[fullname] */
1177+
if (is_arr_upload) {
1178+
snprintf(lbuf, llen, "%s[fullpath][%s]", abuf, array_index);
1179+
} else {
1180+
snprintf(lbuf, llen, "%s[fullpath]", param);
1181+
}
1182+
register_http_post_files_variable(lbuf, filename, &PG(http_globals)[TRACK_VARS_FILES], 0);
1183+
efree(filename);
1184+
11551185
/* Possible Content-Type: */
11561186
if (cancel_upload || !(cd = php_mime_get_hdr_value(header, "Content-Type"))) {
11571187
cd = "";

0 commit comments

Comments
 (0)