<?php $zip=new ZipArchive; $res = $zip->open($name, ZipArchive::CREATE); if ($res === TRUE) { $fileSPLObjects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST); foreach( $fileSPLObjects as $fullFileName => $fileSPLObject ) { if ($fileSPLObject->isDir()) { $zip->addEmptyDir($fullFileName); } elseif ($fileSPLObject->isFile()) { $zip->addFile($fullFileName); } } $zip->close(); } ?>