When I POST with attaching (uploading) a file, I would expect to see the file when I inspect the raw body of the request on the server. I don't.
I am using file_get_contents('php://input')
to see the raw body of the request.
What should I use to see the body of the request with the file content I attached.

- 52,579
- 61
- 190
- 278
2 Answers
AFAIK there is no way to do this.
The manual states:
php://input is not available with enctype="multipart/form-data".
If you have uploaded a file, the MIME type should be multipart/form-data
- so php://input
will not be available.
Having said that, there should normally be no reason why you would need to get the raw body in this scenario. In order to get the file data, you will have to use the $_FILES
array as normal.
If you expand on why you need to do this, I will help you find a solution that fits your needs.

- 87,921
- 11
- 154
- 174
-
The POST method is technically not compatible with REST because it is not [idempotent](http://en.wikipedia.org/wiki/Idempotence). If you want to upload files with REST, you should use the PUT method. I understand that this is not really a practical proposition with a web browser, but if you want to be technically correct then you should not use POST for anything in a REST request. @Wrikken's answer will probably suit your purposes if you want to continue to use POST. – DaveRandom Jan 31 '12 at 09:17
-
I am not using a web browser. How will PUT make it different? – Itay Moav -Malimovka Jan 31 '12 at 14:17
-
PUT requests are idempotent - the effect of more than one identical request will be the same as one request. POST requests will typically result in a change of the state of the server that may be duplicated by a subsequent request, such as a DB insert (thereby making them technically incompatible with REST). If this is not true of your implementation then you can go ahead and use POST, but it will not be technically correct. [This question](http://stackoverflow.com/questions/630453) debates exactly these issues and may help you better understand the issues at play here. – DaveRandom Jan 31 '12 at 14:35
From http://www.php.net/manual/en/wrappers.php.php:
php://input is not available with enctype="multipart/form-data".
... which is stricly true, but you could circumvent it by unsetting enctype
in the webserver before it reaches PHP. The $_FILES
array would be empty then. Assuming Apache with mod_headers:
RequestHeader unset Content-Type

- 69,272
- 8
- 97
- 136
-
`unsetting enctype` - I think you mean unsetting `Content-Type`, which is what `enctype` translates to in the context of a HTTP request... – DaveRandom Jan 30 '12 at 20:07
-
Yeah, same result, but technically more correct stating it that way yes. – Wrikken Jan 30 '12 at 20:10