Translating cURL Command Line to PHP cURL
Seeking assistance in converting a command-line cURL command to its corresponding PHP script, a user presents the following challenge:
curl -b cookie.txt -X PUT \ --data-binary "@test.png" \ -H "Content-Type: image/png" \ "http://hostname/@api/deki/pages/=TestPage/files/=test.png" \ -0
The goal is to incorporate this command into a PHP script, with the following variables:
PHP Script Conversion:
To translate this command line cURL to a PHP script, one can start with the following code:
$pageurl = "http://hostname/@api/deki/pages/=TestPage/files/="; $filename = "test.png"; $theurl = $pageurl . $filename; $ch = curl_init($theurl); curl_setopt($ch, CURLOPT_COOKIE, ...); // -b curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // -X curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binary curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: image/png']); // -H curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0 ...
Additional details regarding specific options can be obtained from the PHP manual: http://www.php.net/manual/en/function.curl-setopt.php
The above is the detailed content of How Can I Translate This cURL Command into a PHP cURL Script?. For more information, please follow other related articles on the PHP Chinese website!