$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"; }
/** * 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) ); } } } } }
/** * Append the contents of an existing zip file to the current, WITHOUT re-compressing the data within it. * * @param string $file the path to the zip file to be added. * @param string $subPath place the contents in the $subPath sub-folder, default is '', and places the * content in the root of the new zip file. * @param AbstractZipWriter $writer Only used by the PHPZip files. Will write all output to the $writer, * instead of the stream. * @return bool true for success. */ public function appendZip($file, $subPath = '', $writer = null) { if ($this->isFinalized) { return false; } $this->writer = $writer; if (!empty($subPath)) { $subPath = \RelativePath::getRelativePath($subPath); $subPath = rtrim($subPath, '/'); if (!empty($subPath)) { $path = explode('/', $subPath); $subPath .= '/'; $nPath = ''; foreach ($path as $dir) { $nPath .= $dir . '/'; $fileEntry = ZipFileEntry::createDirEntry($nPath, time()); $data = $fileEntry->getLocalHeader(); $this->zipWrite($data); $lf = $fileEntry->getLocalHeader(); $lfLen = BinStringStatic::_strlen($lf); $fileEntry->offset = $this->entryOffset; $this->entryOffset += $lfLen; $this->FILES[$this->LFHindex++] = $fileEntry; $this->CDRindex++; } } } if (is_string($file) && is_file($file)) { $handle = fopen($file, 'r'); $this->processStream($handle, $subPath); fclose($handle); } else { if (is_resource($file) && get_resource_type($file) == "stream") { $curPos = ftell($file); $this->processStream($file, $subPath); fseek($file, $curPos, SEEK_SET); } } return true; }