cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

http header issue with file send via php curl

Explorer | Level 3

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.

1 Accepted Solution

Accepted Solutions
Highlighted

Re: http header issue with file send via php curl

Dropboxer
Dropboxer

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.

View solution in original post

1 Reply 1
Highlighted

Re: http header issue with file send via php curl

Dropboxer
Dropboxer

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.

View solution in original post

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?