| Janwillem Borleffs 2004-05-24, 5:32 pm |
| Yang Li Ke wrote:
> Hi guys,
> I am trying to figure how to unzip a file posted from a webform into a
> specific dir on the server but I dont know how to do this without
> having to install other zip components. Is there any ways to do this
> using php only ?
>
> I checked php.net but seems like zip_open only opens the zip but
> doesnt extract it somewhere on the server. Am I right?
>
Yes, you are right, but that's all you need as with PHP's file operation
functions, you can do this yourself.
See the following slightly adjusted example taken from the page at
http://www.php.net/zip:
<?php
$zip = zip_open('/full/path/to/zipfile.zip');
if ($zip) {
while ($zip_entry = zip_read($zip)) {
if (zip_entry_open($zip, $zip_entry, "r")) {
$buf = zip_entry_read($zip_entry,
zip_entry_filesize($zip_entry));
// Write the file
$fp = fopen(zip_entry_name($zip_entry), "wb");
fputs($fp, $buf);
fclose($fp);
zip_entry_close($zip_entry);
}
}
zip_close($zip);
}
?>
JW
|