Using REST API Directly from PHP (no lib)


I’d like to perform both “storage” and “delete” commands on single images from my server using PHP. Since these seem like they should be simple operations, I’d like to just use the REST API directly and not use the uploadcare PHP lib if possible. (It’s just one more github package I’d have to worry about keeping up with changes on, etc.)

I’m not super fluent with CURL, so I was hoping someone could tell me how to perform the following command using PHP.

curl -H “Authorization: Uploadcare.Simple demopublickey:demoprivatekey”

Thanks in advance for any help!


You may want to look at how the lib does these requests under the hood and take parts that you actually need:


Just in case someone else has a similar need, this is what ended up working for me:

$cSession = curl_init(); 

curl_setopt($cSession, CURLOPT_URL,"");
curl_setopt($cSession, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($cSession, CURLOPT_HTTPHEADER, array('Authorization: Uploadcare.Simple demopublickey:demoprivatekey')); 
curl_setopt($cSession, CURLOPT_RETURNTRANSFER,true);

$result = curl_exec($cSession);							// $result holds details about the file that was stored
$status = curl_getinfo($cSession, CURLINFO_HTTP_CODE);	// $status will be 200 if the api call was successful