request_parse_body
request_parse_body
Read and parse the request body and return the result
array **request_parse_body** $options
This function reads the request body and parses it according to the
header. Currently, two content types are
supported:
Content-Type
-
application/x-www-form-urlencoded -
multipart/form-dataThis function is used primarily to parse requests with HTTP verbs other than which do not automatically populate the and superglobals.
multipart/form-data``POST``$_POST``$_FILES
Let op: > consumes the request body without buffering it to the stream.
request_parse_body``php://input
options
The parameter accepts an associative array
to override the following global php.ini settings for parsing of the
request body.
options
-
max_file_uploads -
max_input_vars -
max_multipart_body_parts -
post_max_size -
upload_max_filesizereturns an array pair with the equivalent of at index and at index .
request_parse_body``$_POST``0``$_FILES``1When the request body is invalid, according to the header, a is thrown.
Content-TypeA is thrown when contains invalid keys, or invalid values for the corresponding key.
options
Voorbeeld: example
<?php
// Parse request and store result in the $_POST and $_FILES superglobals.
[$_POST, $_FILES] = request_parse_body();
// Echo the content of some transferred file
echo file_get_contents($_FILES['file_name']['tmp_name']);
?>
Voorbeeld: example with customized options
<?php
// form.php
assert_logged_in();
// Only for this form, we allow a bigger upload size.
[$_POST, $_FILES] = request_parse_body([
'post_max_size' => '10M',
'upload_max_filesize' => '10M',
]);
// Do something with the uploaded files.
?>