Skip to content

Instantly share code, notes, and snippets.

@alissonsilvas
Created January 30, 2017 20:10
Show Gist options
  • Save alissonsilvas/ed4c83344e8405cf3de450d696cd13a6 to your computer and use it in GitHub Desktop.
Save alissonsilvas/ed4c83344e8405cf3de450d696cd13a6 to your computer and use it in GitHub Desktop.
class ZipFiles extends ZipArchive
{
public function Compact($cwd) {
$open = opendir($cwd);
while($folder = readdir($open))
{
if ($folder != '.' && $folder != '..')
{
if (is_dir($cwd.'/'.$folder))
{
$dir = str_replace('./', '',($cwd.'/'.$folder));
$this->addEmptyDir($dir);
$this->Compact($dir);
}
elseif (is_file($cwd.'/'.$folder))
{
$arq = str_replace('./', '',$cwd.'/'.$folder);
$this->addFile($arq);
}
}
}
}
}
$zip = new ZipFiles();
$path = date('Ym');
$arquivo = "../nfephp/files_nfe/homologacao/Xml$path.zip";
chmod($arquivo, 0777);
if ($zip->open($arquivo, ZIPARCHIVE::CREATE) === true){
$zip->Compact(".");
}
$zip->close();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment