Code Snippet
Unzip Files
<?php
$zip = zip_open("zip.zip");
if (is_resource($zip)) {
while ($zip_entry = zip_read($zip)) {
$fp = fopen("zip/".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);
}
?>
Thanks for the snippet! Awesome site. Very helpful.
Wow, learn something new every day, never knew you could unzip files using PHP :) thanks for the snippet
Does this script work with simple PHP installed or any particular library or something needed with PHP ?
i got problem with this message
Fatal error: Call to undefined function zip_open() in /srv/www/vhosts/mysite.com/httpdocs/unzip.php on line 2
Your server may not meet the requirements, see:
http://www.php.net/manual/en/zip.requirements.php
Take it easy as:
and it will unzip file on the server on same file path.
If there are directories in the zip file, it will fail. An extra condition is necessary for properly extracting directories.
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.