note 48767 deleted from ref.zip by danbrown
| From: | danbrown@php.net | Date: | Sun, 25 Oct 2009 13:14:30 +0000 |
| Subject: | note 48767 deleted from ref.zip by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162066@lists.php.net to get a copy of this message | ||
Note Submitter: Mishania AT ketsujin DOT COM
----
I slightly changed the extension of Schore that makes function operate more effiecently - less
number of itterations. This is most important in dealing with HUGE archives. I also add comment to
brief the code. Fits for WIN users.
function unzip($dir,$file) {
$zip = zip_open($dir.$file.".zip"))
if ($zip) {
mkdir($dir.$file);
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));
$hostDir = dirname(zip_entry_name($zip_entry));
/* for root "." directory nothing to be done coase root directory was
created before the while-loop statement */
if ($hostDir != ".") {
$absPathToHostDir = $dir.$file."\\";
/* Convrerts path string upon to FMS & OS-WIN configuration */
foreach ( explode("/",$hostDir) as $k)
$absPathToHostDir = $absPathToHostDir . $k . "\\";
$absPathToHostDir = substr($absPathToHostDir,0,-1);
if (is_file($absPathToHostDir))
unlink($absPathToHostDir);
if (!is_dir($absPathToHostDir))
mkdir($absPathToHostDir);
/* Stores Archive entries BOTH as file: Directories & Files;
for this porpose we need these 2 hereabove [IF] checks */
$fp=fopen($dir.$file."\\".zip_entry_name($zip_entry),"w");
fwrite($fp,$buf);
fclose($fp);
zip_entry_close($zip_entry);
}
}
else {
echo "unable open - ";
return false;
}
} // while-loop end
zip_close($zip);
}
else
return false;
return true;
}