2025 sparked some incredible conversations across our community 👩💻. Discover the highlights and see what’s ahead in 2026.
Forum Discussion
Roshan B.1
10 years agoNew member | Level 1
Downloading images - PHP
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
Replies have been turned off for this discussion
- Steve M.10 years ago
Dropbox Staff
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); - Roshan B.110 years agoNew member | Level 1
That did the trick, thanks :D
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!