Skip to content

Instantly share code, notes, and snippets.

@junaidpv
Forked from anonymous/zip.php
Created July 8, 2013 04:09
Show Gist options
  • Save junaidpv/5946186 to your computer and use it in GitHub Desktop.
Save junaidpv/5946186 to your computer and use it in GitHub Desktop.
PHP script to zip a folder. It can be used on webhosts where functionality of zipping a folder is not enabled.
<?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