Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
FSUInnovation
6 years agoExplorer | Level 4
http header issue with file send via php curl
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.
According to the PHP curl documentation, the 'CURLOPT_HEADER' option is to "to include the header in the output". It doesn't set the headers for the request. You should use the 'CURLOPT_HTTPHEADER' option for that instead.
1 Reply
- Greg-DB6 years ago
Dropbox Community Moderator
According to the PHP curl documentation, the 'CURLOPT_HEADER' option is to "to include the header in the output". It doesn't set the headers for the request. You should use the 'CURLOPT_HTTPHEADER' option for that instead.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!