how to make a file to force download in dropbox sdk

心不动则不痛 提交于 2019-12-25 02:26:56

问题


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


回答1:


Two possibilities:

  1. You could stop passing "true" in the short parameter and thus get a long URL to start with. Then you can just use the dl=1 parameter directly.
  2. 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.




回答2:


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.



来源:https://stackoverflow.com/questions/25180080/how-to-make-a-file-to-force-download-in-dropbox-sdk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!