cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

php file download

php file download

emre
Explorer | Level 4

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 6

Greg-DB
Dropbox Staff
[Cross-linking for reference: https://stackoverflow.com/questions/44000071/dropbox-php-file-download ]

What error/output are you getting?

emre
Explorer | Level 4

xzxzxzxz.png

Attempting to open the file in the browser

How to access direct download link ?

Greg-DB
Dropbox Staff
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

emre
Explorer | Level 4
Thank you so much
That's exactly what I'm looking for :)

 

emre
Explorer | Level 4

Merhaba Greg, ne yazık ki (# files-get temporary link) işe yaramadı

 

I want to make a download button like picture

 

Adsız.png

Greg-DB
Dropbox Staff
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.
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    emre Explorer | Level 4
What do Dropbox user levels mean?