I am newbie to Dropbox API. I have completed the code which upload the file (on my website host) to my Dropbox with a given token. The process runs successfully.
I want to design a page which allows the user select a file (from his/her local machine) and upload directly to my dropbox.
I have an idea that the controller will upload the file to host first then upload to dropbox. However this idea sucks as it takes more time and bandwidth to complete. And I have to delete the file on host after uploading.
This is the code which works on my host:
<?php
require_once "dropbox-sdk/lib/Dropbox/autoload.php";
use \Dropbox as dbx;
$dropbox_config = array(
'key' => 'my key',
'secret' => 'my secret key'
);
$appInfo = dbx\AppInfo::loadFromJson($dropbox_config);
$webAuth = new dbx\WebAuthNoRedirect($appInfo, "PHP-Example/1.0");
$accessToken = 'my token code is given here';
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
// Uploading the file
$f = fopen("working-draft.txt", "rb");
$result = $dbxClient->uploadFile("/working-draft.txt", dbx\WriteMode::add(), $f);
fclose($f);
//print_r($result);
// Get file info
$file = $dbxClient->getMetadata('/working-draft.txt');
// sending the direct link:
$dropboxPath = $file['path'];
$pathError = dbx\Path::findError($dropboxPath);
if ($pathError !== null) {
fwrite(STDERR, "Invalid <dropbox-path>: $pathError\n");
die;
}
// The $link is an array!
$link = $dbxClient->createTemporaryDirectLink($dropboxPath);
$dw_link = $link[0]."?dl=1";
echo "Download link: ".$dw_link."<br>";
?>
And I am using Codeigniter