不使用API​​从Dropbox下载文件

时间:2015-08-13 06:12:02

标签: php dropbox

我的问题很简单。我想通过PHP将Dropbox文件下载到我的服务器。示例Dropbox URL(非实际URL):

https://dl.dropboxusercontent.com/content_link/tnrRxOCfzR4hN70jpWfIpZelnPqCLjPJQ3Ii0S1tDQ3RIgcCVCTphsAzAEiis309?dl=1

当我亲自下载它时,它当然有效。

但是当我尝试使用curlfile_get_contents时,它不起作用。我知道我的curl代码有效,因为我可以使用相同的代码从其他网站下载其他文件。所以我一定会错过从Dropbox下载的东西。

我想在不使用Dropbox API的情况下下载该文件。

任何?

感谢。

编辑: 这是我的cUrl代码:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://dl.dropboxusercontent.com/content_link/SAMPLELINKONLYtDQ3RIgcCVCTphsAzAEiis309?dl=1');
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/5.0)");
    curl_setopt($ch, CURLOPT_REFERER, "http://google.com");
    curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiejar);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookiefile);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);

    $this->output = curl_exec($ch);
    $this->info = curl_getinfo($ch);
    $header_size = $this->info['header_size'];
    $this->head = substr($this->output, 0, $header_size);
    $this->body = substr($this->output, $header_size);

    curl_close($ch);

之后我得到尸体并将其保存到图像文件中:

    file_put_contents($this->download_folder.'/image-' . time() . rand(1000, 9999) . '.jpg', $this->body);

file_put_contents代码完成类似:

    file_put_contents($this->download_folder.'/image-' . time() . rand(1000, 9999) . '.jpg', file_get_contents(https://dl.dropboxusercontent.com/content_link/SAMPLELINKONLYtDQ3RIgcCVCTphsAzAEiis309?dl=1));

0 个答案:

没有答案