$zip = new ZipArchive(); if ($zip->open('example.zip', ZipArchive::CREATE) === TRUE) { $zip->addFile('file1.txt'); $zip->addFile('file2.txt'); $zip->close(); echo 'Zip created successfully'; } else { echo 'Failed to create zip'; }
$zip = new ZipArchive(); if ($zip->open('example.zip') === TRUE) { echo 'Number of files in zip: '.$zip->numFiles; $zip->extractTo('/destination/folder/'); $zip->close(); } else { echo 'Failed to read zip'; }In this example, a zip archive is read and the number of files in it is displayed. The extractTo method is used to extract the files to a destination folder. Both of these examples use the Php ZipArchive package library.