zip_open
With the zip compression file type being the most popular in the world, it would make sense if we could “browse” their contents and details programmatically using PHP, right?
The zip_open() function used in conjunction with other zip_entry_xxx() methods can be used to open a zip file and read its contents. You must have the ZZIPlib library installed along with PHP before zip_open() will work. It’s signature looks like this:
resource zip_open ( string filename)
The idea of the zip_open() function is to load in a zip file and interate through its contents (AKA the compressed files), displaying the attributes and even file contents of the compressed files inside the zip file. Here’s an example:
<?php
$zp = zip_open(”/myfiles/blah.zip”);
while($zipFile = zip_read($zip))
{
echo “Filename: ” . zip_entry_name($zipFile) . “<br>”;
echo “Compressed Size: ” . zip_entry_compresedsize($zipFile) . “<br>”;
echo “Real Size: ” . zip_entry_filesize($zilFile) . “<br><br>”;
}
?>
Zip_open() and the various zip_entry_xxx() methods could come in handy for corporate Intranet setups where employees and other businesses need to share and view compressed documents. Using these functions, you could list the zip files and even extract only one file from the zip, saving bandwidth, time, etc
