Skip to content

Instantly share code, notes, and snippets.

@hyperking
Created June 9, 2014 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyperking/d969eeb5ef97b81b4cb0 to your computer and use it in GitHub Desktop.
Save hyperking/d969eeb5ef97b81b4cb0 to your computer and use it in GitHub Desktop.
Remote Folder to Dropbox folder
<?php
// Set the timezone so filenames are correct
date_default_timezone_set('Europe/London');
// Backup all files in public_html apart from the gz
$siteroot = "/path/to/backup";
$dropbox_email='dropbox@email'; //Dropbox username
$dropbox_pass='pass'; // Dropbox password
include("DropboxUploader.php");
$uploader = new DropboxUploader($dropbox_email, $dropbox_pass);
function FolderToDropbox($dir, $dropbox_link){
$dropbox_folder = 'FolderInDropboxRoot/';
$files = scandir($dir);
foreach($files as $item){
if($item != '.' && $item != '..'){
if(is_dir($dir.'/'.$item)) FolderToDropbox($dir.'/'.$item,$dropbox_link);
else if(is_file($dir.'/'.$item)) {
$clean_dir = str_replace("/path/to/backup", "", $dir);
$dropbox_link->upload($dir.'/'.$item,$dropbox_folder.$clean_dir.'/');
}
}
}
}
FolderToDropbox($siteroot,$uploader);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment