<?php

$zip = new ZipArchive();
$zipFileName = 'folder.zip';
$folderToZip = '../../';

if ($zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE) === true) {
    $files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($folderToZip),
        RecursiveIteratorIterator::LEAVES_ONLY
    );

    foreach ($files as $name => $file) {
        if (!$file->isDir()) {
            $filePath = $file->getRealPath();
            $relativePath = substr($filePath, strlen($folderToZip) + 1);
            $zip->addFile($filePath, $relativePath);
        }
    }

    $zip->close();
    echo 'Zip file created successfully!';
} else {
    echo 'Failed to create zip file.';
}
