note 94921 added to function.ziparchive-extractto
| From: | Anonymous at osu1 dot php dot net | Date: | Thu, 03 Dec 2009 00:38:37 +0000 |
| Subject: | note 94921 added to function.ziparchive-extractto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-163510@lists.php.net to get a copy of this message | ||
I am using this function to extract a specific folder and it's contents from a zip file:
<?php
function extractDir($zipfile, $path) {
if (file_exists($zipfile)) {
$files = array();
$zip = new ZipArchive;
if ($zip->open($zipfile) === TRUE) {
for($i = 0; $i < $zip->numFiles; $i++) {
$entry = $zip->getNameIndex($i);
//Use strpos() to check if the entry name contains the directory we want to extract
if (strpos($entry, "/MyFolder/")) {
//Add the entry to our array if it in in our desired directory
$files[] = $entry;
}
}
//Feed $files array to extractTo() to get only the files we want
if ($zip->extractTo($path, $files) === TRUE) {
return TRUE;
} else {
return FALSE;
}
$zip->close();
} else {
return FALSE;
}
} else {
return FALSE;
}
}
//Run the function
if (extractDir($zipfile, $path)) {
$extracted = "YES! :-D";
} else {
$extracted = "NO! :*(";
}
echo $extracted;
?>
----
Server IP: 64.71.164.2
Probable Submitter: 69.199.146.210
----
Manual Page -- http://www.php.net/manual/en/function.ziparchive-extractto.php
Edit -- https://master.php.net/note/edit/94921
Del: integrated -- https://master.php.net/note/delete/94921/integrated
Del: useless -- https://master.php.net/note/delete/94921/useless
Del: bad code -- https://master.php.net/note/delete/94921/bad+code
Del: spam -- https://master.php.net/note/delete/94921/spam
Del: non-english -- https://master.php.net/note/delete/94921/non-english
Del: in docs -- https://master.php.net/note/delete/94921/in+docs
Del: other reasons-- https://master.php.net/note/delete/94921
Reject -- https://master.php.net/note/reject/94921
Search -- https://master.php.net/manage/user-notes.php