$zip = new ZipArchive(); $zip->open('example.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE); $zip->addFile('file1.txt', 'file1.txt'); $zip->addFile('file2.txt', 'file2.txt'); $zip->close();
$zip = new ZipArchive(); if ($zip->open('example.zip') === true) { $zip->extractTo('/path/to/destination'); $zip->close(); echo 'Files extracted!'; } else { echo 'Failed to extract files!'; }This code opens an existing zip archive named 'example.zip' and extracts its contents to the specified destination folder. If successful, it prints 'Files extracted!' on the screen. Package Library: The PHP ZipArchive library is part of the PHP core, which means that it is included with every installation of PHP.