We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
emre
9 years agoExplorer | Level 4
php file download
Hello, I am trying to download a file with PHP, but I am having trouble with this part of the code. I need an example in this regard
$url = "https://content.dropboxapi.com/2/files/download"; $sAccessToken = "*************************"; $curl = curl_init($url); $aPostData = array('path' => '/test.rar'); $aOptions = array( CURLOPT_POST => true, CURLOPT_HTTPHEADER => array('Content-Type:', 'Authorization: Bearer ' . $sAccessToken, 'Dropbox-API-Arg: ' . json_encode($aPostData) ) , CURLOPT_RETURNTRANSFER => true ); curl_setopt_array($curl, $aOptions); $result = curl_exec($curl); echo $result;
6 Replies
- Greg-DB9 years ago
Dropbox Community Moderator
[Cross-linking for reference: https://stackoverflow.com/questions/44000071/dropbox-php-file-download ]
What error/output are you getting? - emre9 years agoExplorer | Level 4
Attempting to open the file in the browser
How to access direct download link ? - Greg-DB9 years ago
Dropbox Community Moderator
Is that the output you're getting from the PHP code you shared earlier? If so, that is likely just the raw file data, which the browser is trying to display as text. The /2/files/download endpoint does return the raw file data, so you can do with it whatever you need to. E.g., save it to a file, etc.
If you want a link to the file instead, you can use /2/files/get_temporary_link:
https://www.dropbox.com/developers/documentation/http/documentation#files-get_temporary_link - emre9 years agoExplorer | Level 4
Thank you so much
That's exactly what I'm looking for :) - emre9 years agoExplorer | Level 4
Merhaba Greg, ne yazık ki (# files-get temporary link) işe yaramadı
I want to make a download button like picture
- Greg-DB9 years ago
Dropbox Community Moderator
The screenshot you shared shows you trying the /2/files/download endpoint. You can use that to directly return files contents if you'd like.
We discussed using /2/files/get_temporary_link though. That would give you a direct URL for the file contents. This is working correctly as far as I can tell.
In either case, how you use that response is up to you, and exactly how you implement it will depend on the specifics of your app.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 7 hours ago
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 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!