note 80705 added to ref.zip
| From: | rodrigo dot moraes at gmail dot com | Date: | Tue, 29 Jan 2008 15:56:42 +0000 |
| Subject: | note 80705 added to ref.zip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135557@lists.php.net to get a copy of this message | ||
Here's a more simple extended class to add a whole directory recursively, 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/80705
Del: integrated -- https://master.php.net/note/delete/80705/integrated
Del: useless -- https://master.php.net/note/delete/80705/useless
Del: bad code -- https://master.php.net/note/delete/80705/bad+code
Del: spam -- https://master.php.net/note/delete/80705/spam
Del: non-english -- https://master.php.net/note/delete/80705/non-english
Del: in docs -- https://master.php.net/note/delete/80705/in+docs
Del: other reasons-- https://master.php.net/note/delete/80705
Reject -- https://master.php.net/note/reject/80705
Search -- https://master.php.net/manage/user-notes.php