cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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: 

Downloading images - PHP

Downloading images - PHP

Roshan B.1
New member | Level 1

Hi,

I'm trying to download an image with the dropbox SDK for PHP, in the future I'll hopefully use Delta to update.

I'm having trouble saving the image as I'm not actually sure where the image is being stored in PHP. Currently I get a .jpeg file but it is un-openable, I presume it's actually text or something.

The browser does show the image meta so I know it's successfully contacting the dropbox servers. The contents of /Dropbox-SDK are unmodified.

 

Here is my current code:

<?php

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

require_once "Dropbox-SDK/Dropbox/autoload.php";
use \Dropbox as dbx;

$appInfo = dbx\AppInfo::loadFromJsonFile("Dropbox-SDK/Dropbox/config.json");
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");

$accessToken = "XXXXXXXX";
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");

//getDelta($cursor = null, $pathPrefix = null );

//getFile($path = '/Scouts/Images/Glide1.jpeg', $outStream = $login, $rev = null );

$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");

$filename = 'Glide1.jpeg';
$input = '/Scouts/Images/'.$filename;
$output = '/var/www/vhosts/MY/DOMAIN/images/dropbox/'.$filename;

$f = fopen($filename, "w+b");
$fileImage = $dbxClient->getFile($input, $f);
fclose($f);
print_r ($fileImage);
if(file_put_contents($output, $fileImage)){echo '<hr/>File saved successfully!';}
2 Replies 2

Re: Downloading images - PHP

Steve M.
Dropboxer

I think you want this:

$filename = 'Glide1.jpeg';
$input = '/Scouts/Images/'.$filename;
$output = '/var/www/vhosts/MY/DOMAIN/images/dropbox/'.$filename;

$f = fopen($output, "w+b"); // write to $output
$fileImage = $dbxClient->getFile($input, $f);
fclose($f);

Re: Downloading images - PHP

Roshan B.1
New member | Level 1

That did the trick, thanks 😄

Who's talking

Top contributors to this post

  • User avatar
    Roshan B.1 New member | Level 1
  • User avatar
    Steve M. Dropboxer
What do Dropbox user levels mean?
Need more support?