¿Cómo obtengo la información del archivo + el cuerpo con file_get_contents ('php: // input')?

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.
Estoy utilizando file_get_contents('php://input') to see the raw body of the request.
What should I use to see the body of the request con the file content I attached.

preguntado el 30 de enero de 12 a las 19:01

2 Respuestas

AFAIK there is no way to do this.

El manual establece lo siguiente:

php: // entrada no está disponible con enctype = "multipart / form-data".

If you have uploaded a file, the MIME type should be multipart/form-data - asi que php://input no estará disponible.

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.

Respondido el 31 de enero de 12 a las 00:01

The POST method is technically not compatible with REST because it is not idempotente. 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

I am not using a web browser. How will PUT make it different? - Itay Moav -Malimovka

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. Esta pregunta debates exactly these issues and may help you better understand the issues at play here. - DaveRandom

Desde http://www.php.net/manual/en/wrappers.php.php:

php: // la entrada no está disponible con enctype = "multipart / form-data".

... which is stricly true, but you podría circumvent it by unsetting enctype in the webserver antes de it reaches PHP. The $_FILES array would be empty then. Assuming Apache with mod_headers:

RequestHeader unset Content-Type

Respondido el 31 de enero de 12 a las 00:01

unsetting enctype - I think you mean unsetting Content-Type, Que es que enctype translates to in the context of a HTTP request... - DaveRandom

Yeah, same result, but technically more correct stating it that way yes. - Wrikken

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.