Send a PUT request with PHP.

This is a short tutorial on how to send a PUT request using PHP. Generally speaking, the PUT method is used to update a given resource (I will presume that you already know this).

Here is a simple example of a PUT request being carried out with cURL & PHP:

In the code above, we used theĀ CURLOPT_PUT option to send a PUT request.

In my log.php file, which I sent the request to, I logged the REQUEST_METHOD variable from the $_SERVER array. The result:

But what if we want to PUT a file onto the server?

If you look at the PHP code above, you’ll see that I opened the given file before passing its file handle to cURL using the CURLOPT_INFILE option. I also specified the file size in bytes by using the CURLOPT_INFILESIZE option.

Comments

comments