Minimalist helper to use the complete PHP SDK for Dropbox's v2 API Alorel/dropbox-v2-php. Simplifies at best the following uses at Dropbox:
- read/write/delete a file
- list a folder from the path
- list the delta of a folder from the cursor
- get account information of the connected account
Via Composer
$ composer require headoo/dropboxhelper
Load the helper:
<?php
use \Headoo\DropboxHelper\DropboxHelper;
$dropboxHelper = new DropboxHelper($yourAppDropboxToken);
?>
or
<?php
$dropboxHelper = new DropboxHelper();
$dropboxHelper->setToken($yourAppDropboxToken);
?>
Write/Read/Delete a file:
<?php
use \Headoo\DropboxHelper\DropboxHelper;
$dropboxHelper = new DropboxHelper($yourAppDropboxToken);
$dropboxHelper->write('/Path/To/The/File', 'put your content here');
$dropboxHelper->read('/Path/To/The/File');
$dropboxHelper->delete('/Path/To/The/File');
?>
List a folder from the path:
<?php
use \Headoo\DropboxHelper\DropboxHelper;
$dropboxHelper = new DropboxHelper($yourAppDropboxToken);
$oFolder = $dropboxHelper->loadFolderPath('/Path/To/List');
while ($oFolder && ($aMedia = $oFolder->next())) {
if (DropboxHelper::isFolder($aMedia)) {
echo $aMedia['name'] . ' is a folder';
}
if (DropboxHelper::isFile($aMedia)) {
echo $aMedia['name'] . ' is a file';
}
}
?>
List a folder from the cursor:
<?php
use \Headoo\DropboxHelper\DropboxHelper;
$dropboxHelper = new DropboxHelper($yourAppDropboxToken);
$oFolder = $dropboxHelper->loadFolderCursor('--this--is--the--last--cursor--of--the--folder--');
while ($oFolder && ($aMedia = $oFolder->next())) {
if (DropboxHelper::isFolder($aMedia)) {
echo $aMedia['name'] . ' is a folder';
}
if (DropboxHelper::isFile($aMedia)) {
echo $aMedia['name'] . ' is a file';
}
}
echo "The last cursor of the folder is: " . $oFolder->getCursor();
?>
git clone https://github.com/Headoo/DropboxHelper.git
composer install
To test this project with PHPUnit, declare following environment variables:
$ export DROPBOX_TOKEN="YourAppDropboxToken"
$ export DROPBOX_FOLDER_PATH="/Path/In/Your/Dropbox/To/Test"
- Your app Dropbox Token can be found here https://www.dropbox.com/developers/apps
- For folder path, do not forget the leading slash (/)
Then, launch PHPUnit:
$ ./vendor/phpunit/phpunit/phpunit -c phpunit.xml