/** * Add the content to a directory. * * @author Adam Schmalhofer <*****@*****.**> * @author A. Grandt <*****@*****.**> * * @param string $realPath Path on the file system. * @param string $zipPath File path and name to be used in the archive. * @param bool $recursive Add content recursively, default is true. * @param bool $followSymlinks Follow and add symbolic links, if they are accessible, default is true. * @param array &$addedFiles Reference to the added files, this is used to prevent duplicates, default is an empty array. * If you start the function by parsing an array, the array will be populated with the $realPath * and $zipPath kay/value pairs added to the archive by the function. * @param bool $overrideFilePermissions Force the use of the file/dir permissions set in the $extDirAttr * and $extFileAttr parameters. * @param int $extDirAttr Permissions for directories. * @param int $extFileAttr Permissions for files. */ public function addDirectoryContent($realPath, $zipPath, $recursive = true, $followSymlinks = true, &$addedFiles = array(), $overrideFilePermissions = false, $extDirAttr = self::EXT_FILE_ATTR_DIR, $extFileAttr = self::EXT_FILE_ATTR_FILE) { if (file_exists($realPath) && !isset($addedFiles[realpath($realPath)])) { if (is_dir($realPath)) { $this->addDirectory($zipPath, 0, null, $overrideFilePermissions ? $extDirAttr : ZipUtils::getFileExtAttr($realPath)); } $addedFiles[realpath($realPath)] = $zipPath; $iter = new \DirectoryIterator($realPath); foreach ($iter as $file) { /* @var $file \DirectoryIterator */ if ($file->isDot()) { continue; } $newRealPath = $file->getPathname(); $newZipPath = ZipUtils::pathJoin($zipPath, $file->getFilename()); if (file_exists($newRealPath) && ($followSymlinks || !is_link($newRealPath))) { if ($file->isFile()) { $addedFiles[realpath($newRealPath)] = $newZipPath; $this->addLargeFile($newRealPath, $newZipPath, 0, null, $overrideFilePermissions ? $extFileAttr : ZipUtils::getFileExtAttr($newRealPath)); } else { if ($recursive) { $this->addDirectoryContent($newRealPath, $newZipPath, $recursive, $followSymlinks, $addedFiles, $overrideFilePermissions, $extDirAttr, $extFileAttr); } else { $this->addDirectory($zipPath, 0, null, $overrideFilePermissions ? $extDirAttr : ZipUtils::getFileExtAttr($newRealPath)); } } } } } }