Skip to content

Instantly share code, notes, and snippets.

Created July 8, 2013 04:08
Show Gist options
  • Save anonymous/5946181 to your computer and use it in GitHub Desktop.
Save anonymous/5946181 to your computer and use it in GitHub Desktop.
PHP Script to zip folder. It can be used on shared webhosts where the zip functionality is not enabled. From http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php
<?php
$path="../ctest";
$zip = new ZipArchive;
$zip->open('../ctest.zip', ZipArchive::CREATE);
if (false !== ($dir = opendir($path))) {
while (false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
$zip->addFile($path.DIRECTORY_SEPARATOR.$file);
//delete if need
//if($file!=='important.txt')
//unlink($path.DIRECTORY_SEPARATOR.$file);
}
}
}
else {
die('Can\'t read dir');
}
$zip->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment