开发者

Making a PUT request with PHP and CURL

First of all I'm working based on the following assumption: according to the REST architecture you can use PUT to create a new resource, in my case a file with additional informations provided by the user.

If this concept is not correct please let me know so I don't ask an incorrect question from the architectural point of view.

I see there are two things related to PUT request using CURL.

With the following method you can send an array of values just like a normal POST request.

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

and using this:

curl_setopt($ch, CURLOPT_PUT, 1);

a file can be uploaded.

  • Are this two options related ?
  • Are they complementarity ways to send both a f开发者_Python百科ile and some meta information in the same PUT request?
  • What is the solution to upload a file and send additional information for it like category and description

    I'm just trying to mimic the POST functionality

        $post_params['name'] = urlencode('Test User');
        $post_params['file'] = '@'.'/tmp/never_ending_progress_bar2.gif';
    


    CURLOPT_CUSTOMREQUEST is useful when you want / need to do some kind of special request that is not common enough to be supported by itself, via its own option.

    CURLOPT_POST, CURLOPT_PUT, and CURLOPT_GET allow you to send POST / PUT / GET requests -- which are some types of requests that are common enough to have their own options ; which means they don't need you to use CURLOPT_CUSTOMREQUEST.

  • 0

    上一篇:

    下一篇:

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    最新问答

    问答排行榜