Convert command line cURL to PHP cURL
a starting point:
<?php$pageurl = "http://hostname/@api/deki/pages/=TestPage/files/=";$filename = "test.png";$theurl = $pageurl . $filename;$ch = curl_init($theurl);curl_setopt($ch, CURLOPT_COOKIE, ...); // -bcurl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // -Xcurl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); // --data-binarycurl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: image/png']); // -Hcurl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); // -0...?>
See also: http://www.php.net/manual/en/function.curl-setopt.php
You need ...
curl-to-PHP : https://incarnate.github.io/curl-to-php/
"Instantly convert curl commands to PHP code"
Whicvhever cURL you have in command line, you can convert it to PHP with this tool:
https://incarnate.github.io/curl-to-php/
It helped me after long long hours of searching for a solution! Hope it will help you out too! Your solution is this:
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://hostname/@api/deki/pages/=TestPage/files/=test.png");curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$post = array( "file" => "@" .realpath("test.png"));curl_setopt($ch, CURLOPT_POSTFIELDS, $post);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");$headers = array();$headers[] = "Content-Type: image/png";curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);$result = curl_exec($ch);if (curl_errno($ch)) { echo 'Error:' . curl_error($ch);}curl_close ($ch);