Code: Alles auswählen
<?php
     $zip = new ZipArchive;
     $res = $zip->open('DATEINAME.zip');
     if ($res === TRUE) {
         $zip->extractTo('./');
         $zip->close();
         echo 'ok';
     } else {
         $file = "DATEINAME.zip";
         exec("unzip $file 2>&1", $out);
         print(implode("<br>", $out));
     }
?>Code: Alles auswählen
    <?php
    // die maximale Ausführzeit erhöhen
    ini_set("max_execution_time", 3000);
    // Get real path for our folder
    $rootPath = realpath('pfad-zum-Ordner');
    // Initialize archive object
    $zip = new ZipArchive();
    $zip->open('backup.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
    // Create recursive directory iterator
    /** @var SplFileInfo[] $files */
    $files = new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator($rootPath),
        RecursiveIteratorIterator::LEAVES_ONLY
    );
    foreach ($files as $name => $file)
    {
        // Skip directories (they would be added automatically)
        if (!$file->isDir())
        {
            // Get real and relative path for current file
            $filePath = $file->getRealPath();
            $relativePath = substr($filePath, strlen($rootPath) + 1);
            // Add current file to archive
            $zip->addFile($filePath, $relativePath);
        }
    }
    // Zip archive will be created only after closing object
    $zip->close();
    echo "Archiv erfolgreich erstellt.";
    ?>