Using Associative array

When we use Curl option to post some values .We might face some issue where the data posted will not be posted in the web page .Here is a scenario when we got this same kind of issue and that was rectified using associative array
A form having file uploadoption was not posted correctly.
The content type is multi-part/form-data for this form.

The below line of code will set the post fields for the curl session.
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fiels);

The $post_fields can be specified either as querystring parameters or as an associative array.

Initially we had specified the $post_fields as querystring paramter as $post_fields=”field1=value1&field2=value2″;

But this approach didn’t work for the multi-part/form-data forms.

It works fine after changing this code using an associative array as below.

$post_fields = array(“field1” => “value1”, “field2” => “value2”);

Posted in Php Tagged with: ,