note 48767 added to ref.zip
| From: | MishaniaATketsujinDOTCOM at osu1 dot php dot net | Date: | Thu, 06 Jan 2005 16:19:18 +0000 |
| Subject: | note 48767 added to ref.zip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-82845@lists.php.net to get a copy of this message | ||
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;
}
----
Manual Page -- http://www.php.net/manual/en/ref.zip.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48767
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48767&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48767&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48767&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48767&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48767&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48767&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48767&report=yes
Search -- http://master.php.net/manage/user-notes.php