Para comprimir archivos creando un archivo ZIP desde PHP, se puede utilizar el siguiente código
$rootPath = realpath('carpeta_fuente');
$zip = new ZipArchive();
$zip->open('archivo_destino.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
if (!$file->isDir())
{
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
$zip->addFile($filePath, str_replace('\\', '/', $relativePath));
}
}
$zip->close();
Para descomprimir los archivos de un archivo ZIP desde PHP, se puede utilizar el siguiente código
$zip = new ZipArchive;
$res = $zip->open('ubicacion/archivo_fuente.zip');
if ($res === TRUE) {
$zip->extractTo('carpeta_destino/');
$zip->close();
echo 'creado!';
} else {
echo 'error!';
}

