Discuss Dropbox Developer & API
function dropbox_download_zip($folder_path, $file_name) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://content.dropboxapi.com/2/files/download_zip'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); $headers = array(); $headers[] = "Authorization: Bearer " . DROPBOX_TOKEN . ""; $headers[] = "Dropbox-API-Arg: {\"path\": \"$folder_path\"}"; $headers[] = "Content-Type: application/octet-stream; charset=utf-8"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); curl_close($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { $file_name = $file_name . '.zip'; file_put_contents(get_home_path() . '/' . $file_name, $result); $zipFilePath = get_home_path() . $file_name; $zipBaseName = basename($zipFilePath); header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=$zipBaseName"); header("Content-Length: " . filesize($zipFilePath)); readfile($zipFilePath); @unlink($zipFilePath); die(); } }
here is my code, but it only works on a local server, on a real site it produces such an error, why? https://monosnap.com/file/0Dxbpzchbiq8ngZRl42SNEHqbCvmi1
To clarify, is the screenshot you shared showing the rendering of some HTML returned by https://content.dropboxapi.com/2/files/download_zip?
Can you share what the rest of the response is, that is, the response status and headers?
i have to return zip archive data but it returns https://monosnap.com/file/0Dxbpzchbiq8ngZRl42SNEHqbCvmi1
Thanks, but still to clarify, what exactly are you doing to get the result in that second screenshot? That appears to be a Dropbox HTML error page, but the response in the first screenshot indicates that the response was just plain text, not HTML.
That 400 response should indicate that the API request wasn't correctly formatted. The plain text response body should be a more useful error message, so please print that out, e.g., like `echo $result;`.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
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!