Download a thubnails of an image using Dropbox API for php

…衆ロ難τιáo~ 提交于 2019-12-13 21:26:35

问题


I made a script where I download the images from a dropbox folder to my computer using PHP. What I try to do now is to download thumbnail of the images instead of the whole image. For this I use the: GetThumbNail method from the Dropbox API. Here is part of the code:

    // download the files
    $f = fopen($img_name, "w+b");   
    $fileMetadata = $dbxClient->getThumbnail($path, 'jpeg','xl');
    fclose($f);

When I run this the images I get are 0 size and they have no content. Any ideas what I am missing? Thanks D.

EDITED

    $f = fopen($img_name, 'w+b');
    $thumbnailData = $dbxClient->getThumbnail($path, 'jpeg', 'xl');
    fwrite($f, $thumbnailData);
    fclose($f);

回答1:


You're opening and closing $f without ever writing anything into it.

getThumbnail returns an array with two elements: the metadata for the file and the thumbnail data.

So I think you'll want something like this:

$f = fopen($img_name, 'w+b');
list($fileMetadata, $thumbnailData) = $dbxClient->getThumbnail($path, 'jpeg', 'xl');
fwrite($f, $thumbnailData);
fclose($f);


来源:https://stackoverflow.com/questions/27344561/download-a-thubnails-of-an-image-using-dropbox-api-for-php

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