PHP-logoThe other day I needed to automate the unzipping and processing of files contained within a zip archive. Using the existing PHP Zip library and some help off the web, this is what I was left with:

(Note, you need to enable php_zip.dll extension within php.ini in order to use the code below)

$zip = zip_open($zipfilename);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
$fp = fopen($targetdir . zip_entry_name($zip_entry), "w");
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
fwrite($fp,"$buf");
zip_entry_close($zip_entry);
fclose($fp);
}
}
zip_close($zip);

Nifty.