request_parse_body()
request_parse_body() — Read and parse the request body and return the result.
Built-in function of PHP 8.5. The manual lists it as available in PHP 8 >= 8.4.0. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
This function is used primarily to parse multipart/form-data requests with HTTP verbs other than POST which do not automatically populate the $_POST and $_FILES superglobals.
Signature
request_parse_body(?array $options = null): array
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $options | ?array | The options parameter accepts an associative array to override the following global php.ini settings for parsing of the request body. |
Return value
request_parse_body() returns an array pair with the equivalent of $_POST at index 0 and $_FILES at index 1.
Example
A runnable snippet:
// 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']);
All PHP 8.5 built-in functions
Reference card built from the PHP manual page request_parse_body() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.