public function __construct($cmdBinPath = '/bin/tar') { if ($cmdBinPath === null) { throw new UnimplementedFeatureException('no built-in support for GNU Tar'); } parent::__construct($cmdBinPath); }
public function open($sourceFile) { parent::open($sourceFile); if ($this->zipArchive) { $resultCode = $this->zipArchive->open($sourceFile); if ($resultCode !== true) { throw new ArchiverException('ZipArchive::open() returns error code == ' . $resultCode); } } return $this; }
/** * Download all passed files. * @param $args array * @param $request Request */ function downloadAllFiles($args, $request) { // Retrieve the authorized objects. $submissionFiles = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION_FILES); $submission = $this->getAuthorizedContextObject(ASSOC_TYPE_SUBMISSION); // Find out the paths of all files in this grid. $context = $request->getContext(); $filePaths = array(); $fileManager = $this->_getFileManager($context->getId(), $submission->getId()); $filesDir = $fileManager->getBasePath(); foreach ($submissionFiles as $submissionFile) { // Remove absolute path so the archive doesn't include it (otherwise all files are organized by absolute path) $filePaths[str_replace($filesDir, '', $submissionFile->getFilePath())] = $submissionFile->getClientFileName(); } import('lib.pkp.classes.file.FileArchive'); $fileArchive = new FileArchive(); $archivePath = $fileArchive->create($filePaths, $filesDir); if (file_exists($archivePath)) { $fileManager = new FileManager(); if ($fileArchive->zipFunctional()) { $fileManager->downloadFile($archivePath, 'application/x-zip', false, 'files.zip'); } else { $fileManager->downloadFile($archivePath, 'application/x-gtar', false, 'files.tar.gz'); } $fileManager->deleteFile($archivePath); } else { fatalError('Creating archive with submission files failed!'); } }