I'm trying to post to a file service with CDN translating the cli -T option to PHP code, but I don't really know what the equivalent is, or what is the corresponding code that would replicate it. I've seen a options around CURLOPT_HTTPHEADER, but that doesn't seem to work in correspondence to other headers.
The exact thing I'm trying to replicate is this:
curl -XPUT -T "test.png" -v -H "X-Auth-Token:MYTOKEN" -H"Content-Type: text/plain" "https://somecdn.com"
I think it's something like this, but I'm unsure:
$ch = curl_init();
// Set up the options
curl_setopt($ch, CURLOPT_URL, "https://mycdn.com/test.txt");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-Auth-Token: mytoken",
"Content-type: text/plain"
)
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("file" => "@test.txt") );
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
I'm surprised, I suppose, that -T flag doesn't have a similar curl_setopt.
So the precise question is this:
What is the proper way to replicate cURL CLI -T "test.png"
in PHP?