For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > May 2004 > how to unzip ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author how to unzip ?
Yang Li Ke

2004-05-23, 9:31 pm

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?

Thank you
Yang


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



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com