$zip = new ZipArchive; if ($zip->open('example.zip') === TRUE) { $zip->extractTo('/path/to/destination'); $zip->close(); echo 'Files extracted successfully.'; } else { echo 'Failed to extract files.'; }
$zip = new ZipArchive; if ($zip->open('example.zip') === TRUE) { $zip->extractTo('/path/to/destination', array('file1.txt', 'file2.txt')); $zip->close(); echo 'Files extracted successfully.'; } else { echo 'Failed to extract files.'; }This code extracts only file1.txt and file2.txt from the example.zip archive to the directory specified in the $destination variable. The ZipArchive class and the extractTo method are part of the PHP Standard Library.