|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76444 can't read stream from multipart requests
Submitted: 2018-06-11 08:23 UTC Modified: 2021-07-27 12:05 UTC
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: clark at electrobeat dot dk Assigned:
Status: Open Package: Streams related
PHP Version: 7.0.30 OS: debian stretch
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: clark at electrobeat dot dk
New email:
PHP Version: OS:


 [2018-06-11 08:23 UTC] clark at electrobeat dot dk
It's not possible to read the request stream from multipart/form-data requets

$body = file_get_contents('php://input');

It seems like it has been a open bug for many years so I don't get why it has never been fixed!?

If a user uploads a file you can't even check if the data part is gzipped or anything..

It doesn't make sense that you only can read streams from some request streams but not from others!?

Test script:
$boundary = 'jlasdifj439';
$field1 = json_encode(['test' => 123]);
$body = '--'.$boundary."\r\n"
	.'Content-Disposition: form-data; name="json"; filename="file.pdf"'."\r\n"
	.'Content-Type: application/json'."\r\n"
	.'Content-Length: '.strlen($field1)."\r\n\r\n"

$socket = curl_init();
curl_setopt_array($socket, [
	CURLOPT_POST 			=> true,
curl_setopt($socket, CURLOPT_URL, '');
curl_setopt($socket, CURLOPT_HTTPHEADER, [
	'Content-Type: multipart/form-data; boundary='.$boundary,
curl_setopt($socket, CURLOPT_POSTFIELDS, $body);
if(!$response = curl_exec($socket)){
	echo "ERROR!";
echo $response;


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-06-11 08:26 UTC] clark at electrobeat dot dk
want to delete the url to my server
 [2018-06-11 09:07 UTC]
-Type: Bug +Type: Feature/Change Request
 [2018-06-11 09:07 UTC]
It hasn't been fixed because it isn't a bug.
> php://input is not available with enctype="multipart/form-data".

File upload requests are often large. They can't necessarily be buffered to memory, though buffering to a temp file would probably be a reasonable fallback. And obviously being a data stream so it's not naturally seekable.

But it sounds like what you really want is to get the multipart headers. AFAIK that's a brand new idea.
 [2018-06-11 09:28 UTC] clark at electrobeat dot dk
Is it possible to get the headers from the parts of a multipart request?
 [2018-06-11 09:29 UTC] clark at electrobeat dot dk
could anyone please remove the URL in the description to my server..
 [2018-06-11 09:59 UTC]
By "brand new idea" I meant that I've never heard of anyone needing a way to do that, let alone knowing how to.
And looking through the code, I don't see a way to do it.

But I think I see a possible workaround when using nginx and php-fpm: have nginx write the request body to a file (client_body_in_file_only=clean), pass the filename as a CGI environment variable (fastcgi_param REQUEST_BODY_FILE $request_body_file) which PHP will recognize, then you can open and read the file in code too.
 [2021-07-27 12:05 UTC]
Related to request #48219.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Oct 02 06:01:24 2023 UTC