Skip to content

Commit ef375cb

Browse files
bjoern-tantauBjörn Tantau
authored andcommitted
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 9f23891 commit ef375cb

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
@@ -1142,9 +1142,39 @@ 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 $foo_fullpath */
1148+
if (llen < strlen(param) + MAX_SIZE_OF_INDEX + 1) {
1149+
llen = (int)strlen(param);
1150+
lbuf = (char *) safe_erealloc(lbuf, llen, 1, MAX_SIZE_OF_INDEX + 1);
1151+
llen += MAX_SIZE_OF_INDEX + 1;
1152+
}
1153+
1154+
if (is_arr_upload) {
1155+
if (abuf) efree(abuf);
1156+
abuf = estrndup(param, strlen(param)-array_len);
1157+
snprintf(lbuf, llen, "%s_fullpath[%s]", abuf, array_index);
1158+
} else {
1159+
snprintf(lbuf, llen, "%s_fullpath", param);
1160+
}
1161+
1162+
/* Add full path of supplied file for folder uploads via
1163+
* <input type="file" name="files" multiple webkitdirectory>
1164+
*/
1165+
if (!is_anonymous) {
1166+
safe_php_register_variable(lbuf, filename, strlen(filename), NULL, 0);
1167+
}
1168+
1169+
/* Add $foo[fullname] */
1170+
if (is_arr_upload) {
1171+
snprintf(lbuf, llen, "%s[fullpath][%s]", abuf, array_index);
1172+
} else {
1173+
snprintf(lbuf, llen, "%s[fullpath]", param);
1174+
}
1175+
register_http_post_files_variable(lbuf, filename, &PG(http_globals)[TRACK_VARS_FILES], 0);
1176+
efree(filename);
1177+
11481178
/* Possible Content-Type: */
11491179
if (cancel_upload || !(cd = php_mime_get_hdr_value(header, "Content-Type"))) {
11501180
cd = "";

0 commit comments

Comments
 (0)