We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Aziros
9 years agoExplorer | Level 4
UPLOAD FROM HTTP WITH PHP NOT WORKING
Hello ! I want to upload an image (test.png) from the root of my site to my Dropbox but it doesn't work. My php script is in the same folder than image test.png :
$ch = curl_init();
curl_setop...
Greg-DB
Dropbox Community Moderator
9 years agoWhat output are you getting? The HTTP response body from the API should contain either the metadata for the uploaded file, or an error indicating why the upload failed.
Aziros
9 years agoExplorer | Level 4
Hello ! Thanks for interest, I found a solution on Stack Overflow :
$path = 'test.png';
$fp = fopen($path, 'rb');
$size = filesize($path);
$cheaders = array('Authorization: Bearer <TOKEN>',
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: {"path":"/'.$path.'", "mode":"add"}');
$ch = curl_init('https://content.dropboxapi.com/2/files/upload');
curl_setopt($ch, CURLOPT_HTTPHEADER, $cheaders);
curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
curl_close($ch);
fclose($fp);
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!