Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //$directory = 'to';
- // the name of your zip archive to be created
- $zipfile = 'db/'.date('Y-m-d-H-i-s').'_backup_files.zip';
- $filenames = array();
- // function that browse the directory and all subdirectories inside
- function browse($dir) {
- global $filenames;
- if ($handle = opendir($dir)) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != ".." && is_file($dir.'/'.$file)) {
- $filenames[] = $dir.'/'.$file;
- }
- else if ($file != "." && $file != ".." && is_dir($dir.'/'.$file)) {
- browse($dir.'/'.$file);
- }
- }
- closedir($handle);
- }
- return $filenames;
- }
- browse('to');
- browse('cron');
- // creating zip archive, adding browsed files
- $zip = new ZipArchive();
- if ($zip->open($zipfile, ZIPARCHIVE::CREATE)!==TRUE) {
- exit("cannot open <$zipfile>\n");
- }
- foreach ($filenames as $filename) {
- echo "Adding " . $filename . "<br/>";
- $zip->addFile($filename,$filename);
- }
- echo "numfiles: " . $zip->numFiles . "\n";
- echo "status:" . $zip->status . "\n";
- $zip->close();
- ?>
Add Comment
Please, Sign In to add comment