How do I POST an array with multipart/form-data encoding?

If you want associated array you can passing index in the name of the variable.

Up vote 4 down vote favorite share g+ share fb share tw.

In a GET parameter string, or an "x-www-form-urlencoded" POST request, it's possible to specify an array of parameters by naming them with brackets (e.g. "name"). Is there a "correct" (or at least a wide-spread convention) way to specify an array of parameters with a "multipart/form-data" POST request? Would the following be correct?

Content-Type: multipart/form-data; boundary=--abc --abc Content-Disposition: form-data; name="name" first index --abc Content-Disposition: form-data; name="name" second index If it varies by platform, I'm interested in the convention for Apache/PHP. Php apache http post multipartform-data link|improve this question asked Apr 3 at 23:15DougW3,14311043 92% accept rate.

If you want associated array you can passing index in the name of the variable: Content-Type: multipart/form-data; boundary=--abc --abc Content-Disposition: form-data; name="namefirst" first value --abc Content-Disposition: form-data; name="namesecond" second value Then on php level print_r($_POST) would give you Array ( name => Array ( first => first value second => second value ) ) If just normal ordered array then same as you did: Content-Type: multipart/form-data; boundary=--abc --abc Content-Disposition: form-data; name="name" first index --abc Content-Disposition: form-data; name="name" second index Then on php level print_r($_POST) would give you Array ( name => Array ( 0 => first index 1 => second index ) ) Params with in their names translating into arrays on a server side is a feature specific to PHP (http://www.php.net/manual/en/faq.html.php#faq.html.arrays). As for multipart encoding you can find more in RFC: http://www.ietf.org/rfc/rfc1867.txt.

Thanks Alexei. Do you happen to have a reference to any spec or documentation that defines this? Specifically with regard to a multipart POST vs a standard urlencoded one?

– DougW Apr 4 at 0:58 I've added couple of links to the answer – Alexei Tenitski Apr 4 at 3:08 I'm definitely being nit-picky here, but I do want to point out that the PHP docs only mention this convention with regard to web forms which always POST via x-www-form-urlencoded. I'm guessing that by the time POST variables get handed off from Apache to PHP that there is no distinction between content types, but I have not actually read anything that confirms that. And there are definitely a lot of seemingly safe assumptions about PHP that turn out to be disastrously incorrect.

I'll make sure I verify this. – DougW Apr 4 at 18:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions