Skip to content

Instantly share code, notes, and snippets.

@longnz
Last active April 5, 2017 20:54
Show Gist options
  • Save longnz/5261780 to your computer and use it in GitHub Desktop.
Save longnz/5261780 to your computer and use it in GitHub Desktop.
zip folder in php
<?php
$zip = new ZipArchive;
$bkfile = '../export/backup/backup-source-' . date('dd-mm-yy') . '.zip';
$zip->open($bkfile, ZipArchive::CREATE);
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("../../"));
// iterate over the directory
// add each file found to the archive
foreach ($iterator as $key => $value) {
if (in_array(substr($key, strrpos($key, '/') + 1), array('.', '..')))
continue;
$zip->addFile(realpath($key), $key) or die("ERROR: Could not add file: $key");
}
$zip->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment