PUTting data fields with PHP cURL
This is a little post about how to PUT multiple data fields using the PHP cURL extension. Why I wanted to do this in the first place is beyond the scope of this post, since its quite a long story. The curl command line allows data fields to be sent with a PUT request, and I wanted to do the same from PHP. Here is a snippet of code to show how I did it.
$data = array("a" => $a); $ch = curl_init($this->_serviceUrl . $id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data)); $response = curl_exec($ch); if(!$response) { return false; }
I'm putting this here so I remember for next time - if it helps you as well then even better :)

Thx !
Pingback: SugarCRM Developer Blog » Blog Archive » HOWTO: Do PUT requests with PHP cURL without writing to a file
You finally gave me the answer I was looking for with PUT variables - http_build_query(). Simple answer yet so hard to find! Thanks!
Brilliant!!! I'd been looking high and low for a SIMPLE example of using PUT with CURL in PHP but none of the examples worked or were way too complex for my needs. This little snipped of code was exactly what I needed to get some of my own code working :)
Many thanks for sharing...