PHP code example of phpgt / sync
1. Go to this page and download the library: Download phpgt/sync library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpgt / sync example snippets
$source = "/var/www/example.com";
$destination = "/var/backup/example.com";
try {
$sync = new DirectorySync($source, $destination);
$sync->exec(DirectorySync::COMPARE_FILEMTIME);
}
catch(SyncException $exception) {
fwrite(STDERR, "Error performing sync: " . $exception->getMessage());
exit(1);
}
echo "Sync complete!" . PHP_EOL;
echo "Changed: " . count($sync->getCopiedFilesList());
echo "Deleted: " . count($sync->getDeletedFilesList());
echo "Skipped: " . count($sync->getSkippedFilesList());