/** * 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 = \RelativePath::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) ); } } } } }
$f .= "\r\n36: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-37.jpg"), "images/rossi-perfectisboring-37.jpg"); $f .= "\r\n37: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-38.jpg"), "images/rossi-perfectisboring-38.jpg"); $f .= "\r\n38: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-39.jpg"), "images/rossi-perfectisboring-39.jpg"); $f .= "\r\n39: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-40.jpg"), "images/rossi-perfectisboring-40.jpg"); $f .= "\r\n40: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-41.jpg"), "images/rossi-perfectisboring-41.jpg"); $f .= "\r\n41: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-42.jpg"), "images/rossi-perfectisboring-42.jpg"); $f .= "\r\n42: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-43.jpg"), "images/rossi-perfectisboring-43.jpg"); $f .= "\r\n43: " . getMem(); $zip->addLargeFile(\RelativePath::pathJoin($testPath, "images/rossi-perfectisboring-44.jpg"), "images/rossi-perfectisboring-44.jpg"); $f .= "\r\n44: " . getMem(); $f .= "\r\n\r\nFinal:" . getMem(); $zip->addFile($f, "mem.txt"); $rv = $zip->finalize(); // If non-fatal errors occurred during execution, this will append them // to the end of the generated file. // It'll create an invalid Zip file, however chances are that it is invalid // already due to the error happening in the first place. // The idea is that errors will be very easy to spot. if (!empty($errors)) { echo "\n<pre>\n**************\n*** ERRORS ***\n**************\n\n$errors\n</pre>\n"; }