Website Backup to Dropbox using PHP
Dropbox auto backup can be done using PHP as explained in following steps:- Download Dropbox SDK.
- Login to Dropbox.
- Get AccessToken for your login ID.
- Click this link -> Create new App & get its API app key, secret value.
- Store API key, secret key in JSON format.
- Invoke SDK upload functions from PHP.
PHP Code to Upload file to Dropbox
Copy the below PHP code to your web server and replace the required values marked within ‘<>’ with actual values. This code can be executed from your server, either using CRON jobs or any possible methods in your server than can execute the PHP code. If you are using a CPANEL and want to know how to schedule a PHP code in CRON, refer this page.<?php
echo "\n Dropbox Backup Starts" ;
require_once "/home/<FOLDER_PATH_WHERE_SDK_FILE_IS_UPLOADED>/dropbox-sdk/Dropbox/autoload.php";
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("<JSON_FILE_WITH_KEY_AND_SECRET.JSON>");
$accessToken = "<ACCESS_TOKEN_OBTAINED_FROM_DROPBOX_APP>";
$dropboxUserId = "<EMAIL_ID_FOR_YOUR_DROPBOX_APP>";
$dbxClient = new dbx\Client($accessToken, "PHP-Example/1.0");
$accountInfo = $dbxClient->getAccountInfo();
$f = fopen($outputFilePath , "rb");
$result = $dbxClient->uploadFile("/<TARGET_FILE_NAME_IN_DROPBOX>", dbx\WriteMode::add(), $f);
fclose($f);
echo($result);
echo "\n Upload Ends" ;
?>