-1

I want to learn how HTTP PUT method is used with PHP?

I googled at the web and found some tutorials about it with cURL.

But I dont know how to use it (Like REST API).

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
  • 1
    and what about http://php.net/manual/en/features.file-upload.put-method.php – pes502 Mar 03 '16 at 08:27
  • 2
    Do you want to receive or send the PUT request ? – Daan Mar 03 '16 at 08:28
  • i want to update or delete record at the same id. fox ex:http://somepage.com/users/1 – Azer Qurbanov Mar 03 '16 at 08:29
  • If you know how to use GET or POST then its the same regarding usage. The difference between POST and PUT is that a PUT is usually used to get the information to update data server side and POST should send the informationn for creating new data. – B001ᛦ Mar 03 '16 at 08:40
  • @Daan the only proper way to **recieve** data is using GET – B001ᛦ Mar 03 '16 at 08:41

1 Answers1

1
    $data = array("field" => "value");
    $ch = curl_init($yourUrl);

    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);
jeoj
  • 633
  • 6
  • 9
  • I woudl like to say that if url is same how can i differentiate PUT with GET? for ex: – Azer Qurbanov Mar 03 '16 at 10:26
  • Well then there's nothing that separates the requests, other than the method used, right? PUT is often used for updating resources on the server, GET usually for fetching data. – jeoj Mar 03 '16 at 12:44