cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Downloading images - PHP

New member | Level 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
Highlighted

Re: Downloading images - PHP

Dropboxer
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);
Highlighted

Re: Downloading images - PHP

New member | Level 1
New member | Level 1

That did the trick, thanks :D

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?