I am using dropbox php sdk and i want to download the file through the browser . I have a file preview link But away to understand how can i download the file . I am using the function
function GetLink($dropbox_file, $preview=true, $short=true, &$expires=null)
{
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
$url = $this->apiCall(($preview?"shares":"media")."/$this->rootPath/$dropbox_file", "POST", array('locale' => null, 'short_url'=> $preview ? $short : null));
$expires = strtotime($url->expires);
return $url->url;
}
and this is producing a link to preview the file like https://db.tt/S3znA2kE and if i open this link it becomes https://www.dropbox.com/s/64h549xaofsm67p/readme.txt i know file can download if i will pass ?dl=1 but can't understand HOW
Two possibilities:
short
parameter and thus get a long URL to start with. Then you can just use the dl=1
parameter directly.If, for some reason, you need to get a short URL, you could then expand it by doing an HTTP HEAD and looking at the returned Location
header. E.g. (using curl
):
$ curl -I https://db.tt/S3znA2kE
HTTP/1.1 302 FOUND
Server: nginx
Date: Thu, 07 Aug 2014 21:16:19 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
location: https://www.dropbox.com/s/64h549xaofsm67p/readme.txt
pragma: no-cache
cache-control: no-cache
After you have the full expanded URL, you can modify it to use the dl=1
parameter.
Then you might need to crawl actual url using this example or I think you can grab content and point within DOM and swing back to url.