uploadFile('backup.zip');//file or folder to upload to dropbox //echo '
';print_r($bk);exit;
        @unlink('backup.zip');
	echo 'Upload Complete';
        }
} else {
	echo "

Please install via composer.json

"; echo "

Install Composer instructions: https://getcomposer.org/doc/00-intro.md#globally

"; echo "

Once composer is installed navigate to the working directory in your terminal/command promt and enter 'composer install'

"; exit; } // Here the magic happens :) function zipData($source, $destination) { if (extension_loaded('zip')) { if (file_exists($source)) { $zip = new ZipArchive(); if ($zip->open($destination, ZIPARCHIVE::CREATE)) { //$source = realpath($source); //echo $source;exit; if (is_dir($source)) { $iterator = new RecursiveDirectoryIterator($source); // skip dot files while iterating $iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS); $files = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { // $file = realpath($file); if (is_dir($file)) { $zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); } else if (is_file($file)) { $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file)); } } } else if (is_file($source)) { $zip->addFromString(basename($source), file_get_contents($source)); } } return $zip->close(); } } return false; } class Backup { private $dbxClient; private $projectFolder; /** * __construct pass token and project to the client method * @param string $token authorization token for Dropbox API * @param string $project name of project and version * @param string $projectFolder name of the folder to upload into */ public function __construct($token, $projectFolder) { $this->dbxClient = new Spatie\Dropbox\Client($token); $this->projectFolder = $projectFolder; } /** * upload set the file or directory to upload * @param [type] $dirtocopy [description] * @return [type] [description] */ public function upload($dirtocopy) { if (!file_exists($dirtocopy)) { exit("File $dirtocopy does not exist"); } else { //if dealing with a file upload it if (is_file($dirtocopy)) { $this->uploadFile($dirtocopy); } else { //otherwise collect all files and folders $iter = new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator($dirtocopy, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST, \RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied" ); //loop through all entries foreach ($iter as $file) { $words = explode('/',$file); $stop = end($words); //if file is not in the ignore list pass to uploadFile method if (!in_array($stop, $this->ignoreList())) { $this->uploadFile($file); } } } } } /** * uploadFile upload file to dropbox using the Dropbox API * @param string $file path to file */ public function uploadFile($file, $mode = 'add') { $path = "/".$this->projectFolder."/$file"; $contents = file_get_contents($file); //if the contents is not empty upload otherwise do nothing if (! empty($contents)) { $this->dbxClient->upload($path, $contents, $mode); } } /** * ignoreList array of filenames or directories to ignore * @return array */ public function ignoreList() { return array( '.DS_Store', 'cgi-bin' ); } }