Last Updated: October 31, 2018
·
39.08K
· marlonlandaverde

Sending PUT data through PHP cURL

For PHP Developers, trying to write a RESTful API can sometimes get a little clunky, especially when you're working with PUT. Here's how send a PUT request using cURL in PHP:

$data = array("woo" => "coderwall");

$ch = curl_init();

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);

1 Response
Add your response

Hi, thanks for this. Really helpful! Just wondering how I add the URL for the API to this script please?

over 1 year ago ·