note 80695 added to ref.zip
| From: | rodrigo dot moraes at gmail dot com | Date: | Tue, 29 Jan 2008 14:19:27 +0000 |
| Subject: | note 80695 added to ref.zip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135543@lists.php.net to get a copy of this message | ||
Here's a more simple class to add a whole directory recursively, including files and keeping
the same structure. It uses SPL.
<?php
class MyZipArchive extends ZipArchive
{
/**
*
* Adds a directory recursively.
*
* @param string $filename The path to the file to add.
*
* @param string $localname Local name inside ZIP archive.
*
*/
public function addDir($filename, $localname)
{
$this->addEmptyDir($localname);
$iter = new RecursiveDirectoryIterator($filename);
foreach ($iter as $fileinfo) {
if (! $fileinfo->isFile() && !$fileinfo->isDir()) {
continue;
}
$method = $fileinfo->isFile() ? 'addFile' : 'addDir';
$this->$method($fileinfo->getPathname(), $localname . '/' .
$fileinfo->getFilename());
}
}
}
?>
----
Server IP: 200.185.126.110
Probable Submitter: 189.7.156.232
----
Manual Page -- http://www.php.net/manual/en/ref.zip.php
Edit -- https://master.php.net/note/edit/80695
Del: integrated -- https://master.php.net/note/delete/80695/integrated
Del: useless -- https://master.php.net/note/delete/80695/useless
Del: bad code -- https://master.php.net/note/delete/80695/bad+code
Del: spam -- https://master.php.net/note/delete/80695/spam
Del: non-english -- https://master.php.net/note/delete/80695/non-english
Del: in docs -- https://master.php.net/note/delete/80695/in+docs
Del: other reasons-- https://master.php.net/note/delete/80695
Reject -- https://master.php.net/note/reject/80695
Search -- https://master.php.net/manage/user-notes.php