views:

1452

answers:

2

I want to receive the following HTTP request in PHP:

Content-type: multipart/form-data;boundary=main_boundary

--main_boundary
Content-type: text/xml
<?xml version='1.0'?>
<content>
Some content goes here
</content>

--main_boundary
Content-type: multipart/mixed;boundary=sub_boundary

  --sub_boundary
  Content-type: application/octet-stream

  File A contents

  --sub_boundary
  Content-type: application/octet-stream

  File B contents

  --sub_boundary

--main_boundary--

(Note: I have indented the sub-parts only to make it more readable for this post.)

I'm not very fluent in PHP and would like to get some help/pointers to figure out how to receive this kind of multipart form request in PHP code. I have once written some code where I received a standard HTML form and then I could access the form elements by using their name as index key in the "$HTTP_GET_VARS" array, but in this case there are no form element names, and the form data parts are not linear (i.e. sub parts = multilevel array).

Grateful for any help!

/Robert

A: 

Uploadeds files will be accessible through the $_FILE global variable, other parameters will be accessible trough the $_GET global variable.

gizmo
+1  A: 

"$HTTP_GET_VARS", "$HTTP_POST_VARS", ect. is an obsolete notation, you should be using $_GET, $_POST, etc.

Now, the file contents should be in the $_FILES global array, whereas, if there are no element names, I'm not sure about whether the rest of the content will show up in $_POST. Anyway, if always_populate_raw_post_data setting is true in php.ini, the data should be in $HTTP_RAW_POST_DATA. Also, the whole request should show up when reading php://input.

Nouveau
Thanks for your reply!I guess the most decent solution would be to name the fields. Do you know what HTTP headers to use for this task?
sharkin
Thanks for this answer, it was helpful. Note: There are cases where $HTTP_RAW_POST_DATA is populated even if always_populate_raw_post_data is false. This is what worked for me.
sherbang