I keep getting errors in my php code regarding a missing authorization header in my http request using curl. This is what my code looks like:
$doc = $_FILES['Resume'];
$filename = $doc['tmp_name'];
$dropbox_token = "token";
$dropbox_url = "https://content.dropboxapi.com/2/files/upload";
/*$dropbox_api_headers = array('Authorization: Bearer '. $dropbox_token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"path"=> '/'. basename($filename),
"mode" => "add",
"autorename" => true,
"mute" => false
)
)
);*/
$opendoc = fopen($filename, 'rb');
$docsize = $_FILES['Resume']['size'];
$d1curl = curl_init();
$timeout = 50;
curl_setopt($d1curl, CURLOPT_URL, $dropbox_url);
curl_setopt($d1curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($d1curl, CURLOPT_HEADER, [
utf8_encode('Authorization: Bearer ' . $dropbox_token),
utf8_encode('Content-Type: application/octet-stream'),
utf8_encode('Dropbox-API-Arg: '.
json_encode(
array(
"path"=> '/'. basename($filename),
"mode" => "add",
"autorename" => true,
"mute" => false
)))]);
curl_setopt($d1curl, CURLOPT_POST, true);
curl_setopt($d1curl, CURLOPT_POSTFIELDS, fread($opendoc, $docsize));
curl_setopt($d1curl, CURLOPT_RETURNTRANSFER, true);
$dropbox_upload = curl_exec($d1curl);
$http_request = curl_getinfo($d1curl, CURLINFO_HTTP_CODE);
echo $dropbox_upload;
echo $http_request;
curl_close($d1curl);
fclose($opendoc);
I wonder why dropbox is giving me for errors as I followed similiar instructions seen on stackoverflow for file send and also referenced the api explorer.