reenadak

folder backup script

Sep 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. <?php
  2. //$directory = 'to';
  3. // the name of your zip archive to be created
  4. $zipfile = 'db/'.date('Y-m-d-H-i-s').'_backup_files.zip';
  5. $filenames = array();
  6. // function that browse the directory and all subdirectories inside
  7. function browse($dir) {
  8. global $filenames;
  9. if ($handle = opendir($dir)) {
  10. while (false !== ($file = readdir($handle))) {
  11. if ($file != "." && $file != ".." && is_file($dir.'/'.$file)) {
  12. $filenames[] = $dir.'/'.$file;
  13. }
  14. else if ($file != "." && $file != ".." && is_dir($dir.'/'.$file)) {
  15. browse($dir.'/'.$file);
  16. }
  17. }
  18. closedir($handle);
  19. }
  20. return $filenames;
  21. }
  22. browse('to');
  23. browse('cron');
  24. // creating zip archive, adding browsed files
  25. $zip = new ZipArchive();
  26. if ($zip->open($zipfile, ZIPARCHIVE::CREATE)!==TRUE) {
  27. exit("cannot open <$zipfile>\n");
  28. }
  29. foreach ($filenames as $filename) {
  30. echo "Adding " . $filename . "<br/>";
  31. $zip->addFile($filename,$filename);
  32. }
  33. echo "numfiles: " . $zip->numFiles . "\n";
  34. echo "status:" . $zip->status . "\n";
  35. $zip->close();
  36. ?>
Add Comment
Please, Sign In to add comment