Last active
November 18, 2015 02:47
-
-
Save stevenwoods/6131e92ac4d5958017a5 to your computer and use it in GitHub Desktop.
Dropbox Upload File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Download the SDK and follow the instructions on generating the parameters for auth.json here: | |
https://www.dropbox.com/developers-v1/core/start/php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"key": "key","secret": "secrety","access_token":"access_token"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once __DIR__."/lib/Dropbox/strict.php"; | |
require_once __DIR__.'/lib/Dropbox/autoload.php'; | |
use \Dropbox as dbx; | |
list($accessToken, $host) = dbx\AuthInfo::loadFromJsonFile('auth.json'); | |
$locale = null; | |
$client = new dbx\Client($accessToken, "upload", $locale, $host); | |
$sourcePath = 'test.txt'; | |
$dropboxPath = '/test.txt'; | |
$pathError = dbx\Path::findErrorNonRoot($dropboxPath); | |
if ($pathError !== null) { | |
fwrite(STDERR, "Invalid <dropbox-path>: $pathError\n"); | |
die; | |
} | |
$size = null; | |
if (\stream_is_local($sourcePath)) { | |
$size = \filesize($sourcePath); | |
} | |
$fp = fopen($sourcePath, "rb"); | |
$metadata = $client->uploadFile($dropboxPath, dbx\WriteMode::add(), $fp, $size); | |
fclose($fp); | |
print_r($metadata); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment