I am wanting to zip some files up into a single temporary file for download. I want to keep it simple and was hoping to utilize the xPDOZip class already in the modx core. I've tried to backtrack the calls through the build transport functions but I'm having trouble putting the file into the archive. The test.zip file is created and no errors display or logged, but there is no document in the test archive.
Here is my preliminary test code:
$source = '/file/on/the/server/filename.doc';
$filename = '/assets/test.zip';
$packed = false;
$packResults = false;
$errors = array();
if (class_exists('ZipArchive', true) && $modx->loadClass('compression.xPDOZip', XPDO_CORE_PATH, true, true)) {
$archive = new xPDOZip($modx, $filename, array(xPDOZip::CREATE => true, xPDOZip::OVERWRITE => true));
if ($archive) {
$packResults = $archive->pack("{$path}{$source}", array(xPDOZip::ZIP_TARGET => "{$source}/"));
$archive->close();
if (!$archive->hasError() && !empty($packResults)) {
$packed = true;
} else {
$errors = $archive->getErrors();
}
}
} elseif (class_exists('PclZip') || include(XPDO_CORE_PATH . 'compression/pclzip.lib.php')) {
$archive = new PclZip($filename);
if ($archive) {
$packResults = $archive->create("{$path}{$source}", PCLZIP_OPT_REMOVE_PATH, "{$path}");
if ($packResults) {
$packed = true;
} else {
$errors = $archive->errorInfo($modx->getDebug() === true);
}
}
}
if (!$packed) {
$modx->log(modX::LOG_LEVEL_ERROR, "Error packing {$path}{$source} to {$filename}: " . print_r($errors, true));
}
return $packed;
Any help would be appreciated.