$zip = new ZipArchive; if ($zip->open('example.zip') === TRUE) { // add new file to archive $zip->addFile('new_file.txt'); // close the archive $zip->close(); echo 'Archive updated and closed.'; } else { echo 'Error opening archive.'; }
$zip = new ZipArchive; if ($zip->open('example.zip') === TRUE) { // extract all files from archive $zip->extractTo('extracted_files/'); // close the archive $zip->close(); echo 'Archive extracted and closed.'; } else { echo 'Error opening archive.'; }In this example, the ZipArchive object is opened and all files are extracted to a directory. The close method is then called to close the archive. The ZipArchive function is a built-in PHP library for working with zip archives.