Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
request_parse_body() keeps files uploaded during startup parsing
--POST_RAW--
Content-Type: multipart/form-data; boundary=---------------------------84000087610663814162942123332
-----------------------------84000087610663814162942123332
Content-Disposition: form-data; name="file_name"; filename="original_file_name.txt"
Content-Type: text/plain

file data
-----------------------------84000087610663814162942123332--
--FILE--
<?php

$tmp_name = $_FILES['file_name']['tmp_name'];
var_dump(is_uploaded_file($tmp_name));

var_dump(request_parse_body());

var_dump(is_uploaded_file($tmp_name));

$dst = __DIR__ . '/multipart_after_startup_parse.txt';
var_dump(move_uploaded_file($tmp_name, $dst));
var_dump(file_get_contents($dst));

?>
--CLEAN--
<?php
@unlink(__DIR__ . '/multipart_after_startup_parse.txt');
?>
--EXPECT--
bool(true)
array(2) {
[0]=>
array(0) {
}
[1]=>
array(0) {
}
}
bool(true)
bool(true)
string(9) "file data"
45 changes: 45 additions & 0 deletions ext/standard/tests/http/request_parse_body/multipart_twice.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
--TEST--
request_parse_body() called twice keeps files uploaded by the first call
--ENV--
REQUEST_METHOD=PUT
--POST_RAW--
Content-Type: multipart/form-data; boundary=---------------------------84000087610663814162942123332
-----------------------------84000087610663814162942123332
Content-Disposition: form-data; name="file_name"; filename="original_file_name.txt"
Content-Type: text/plain

file data
-----------------------------84000087610663814162942123332--
--FILE--
<?php

[, $files] = request_parse_body();
$tmp_name = $files['file_name']['tmp_name'];
var_dump(is_uploaded_file($tmp_name));

var_dump(request_parse_body());

var_dump(is_uploaded_file($tmp_name));

$dst = __DIR__ . '/multipart_twice.txt';
var_dump(move_uploaded_file($tmp_name, $dst));
var_dump(file_get_contents($dst));

?>
--CLEAN--
<?php
@unlink(__DIR__ . '/multipart_twice.txt');
?>
--EXPECT--
bool(true)
array(2) {
[0]=>
array(0) {
}
[1]=>
array(0) {
}
}
bool(true)
bool(true)
string(9) "file data"
9 changes: 5 additions & 4 deletions main/rfc1867.c
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
size_t array_len = 0;
int64_t total_bytes = 0, max_file_size = 0;
int skip_upload = 0, anonymous_index = 0;
HashTable *uploaded_files = NULL;
multipart_buffer *mbuff;
zval *array_ptr = (zval *) arg;
bool throw_exceptions = SG(request_parse_body_context).throw_exceptions;
Expand Down Expand Up @@ -792,9 +791,11 @@ SAPI_API SAPI_POST_HANDLER_FUNC(rfc1867_post_handler)
/* Initialize $_FILES[] */
zend_hash_init(&PG(rfc1867_protected_variables), 8, NULL, NULL, 0);

ALLOC_HASHTABLE(uploaded_files);
zend_hash_init(uploaded_files, 8, NULL, free_filename, 0);
SG(rfc1867_uploaded_files) = uploaded_files;
/* request_parse_body() may parse the body again, keep tracking earlier uploads */
if (!SG(rfc1867_uploaded_files)) {
ALLOC_HASHTABLE(SG(rfc1867_uploaded_files));
zend_hash_init(SG(rfc1867_uploaded_files), 8, NULL, free_filename, 0);
}

if (Z_TYPE(PG(http_globals)[TRACK_VARS_FILES]) != IS_ARRAY) {
/* php_auto_globals_create_files() might have already done that */
Expand Down
Loading