<?php 

if(isset($_POST['filename']) && $_POST['filename']){
    $filename       = $_POST['filename'];
    $filenameZip    = $_POST['filename'].".zip";
    $rootPath       = realpath($filename);

    $zip = new ZipArchive();
    $zip->open($filenameZip, 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, $relativePath);
        }
    }
    $zip->close();

    header("Location: ".$filenameZip);
}
?>

<form action="" method="post">
    <input type="text" name="filename" />
    <input type="submit" />
</form>