grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026fatal("Specified directory for zip file extraction does not exist."); if (defined('SUITE_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) { return false; } } $zip = new ZipArchive; $res = $zip->open(UploadFile::realpath($zip_archive)); // we need realpath here for PHP streams support if ($res !== true) { $GLOBALS['log']->fatal(sprintf(sprintf("ZIP Error(%d): Status(%s)", $res, $zip->status))); if (defined('SUITE_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) { return false; } } if ($archive_file !== null) { $res = $zip->extractTo(UploadFile::realpath($zip_dir), $archive_file); } else { $res = $zip->extractTo(UploadFile::realpath($zip_dir)); } if ($res !== true) { $GLOBALS['log']->fatal(sprintf(sprintf("ZIP Error(%d): Status(%s)", $res, $zip->status))); if (defined('SUITE_PHPUNIT_RUNNER') || defined('SUGARCRM_INSTALL')) { return false; } } return true; } function zip_dir($zip_dir, $zip_archive) { if (!is_dir($zip_dir)) { $GLOBALS['log']->fatal("Specified directory for zip file extraction does not exist."); return false; } $zip = new ZipArchive(); $zip->open(UploadFile::realpath($zip_archive), ZIPARCHIVE::CREATE|ZIPARCHIVE::OVERWRITE); // we need realpath here for PHP streams support $path = UploadFile::realpath($zip_dir); $chop = strlen($path)+1; $dir = new RecursiveDirectoryIterator($path); $it = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::SELF_FIRST); foreach ($it as $k => $fileinfo) { // Bug # 45143 // ensure that . and .. are not zipped up, otherwise, the // CENT OS and others will fail when deploying module $fileName = $fileinfo->getFilename(); if ($fileName == "." || $fileName == "..") { continue; } $localname = str_replace("\\", "/", substr($fileinfo->getPathname(), $chop)); // ensure file if ($fileinfo->isDir()) { $zip->addEmptyDir($localname."/"); } else { $zip->addFile($fileinfo->getPathname(), $localname); } } } /** * Zip list of files, optionally stripping prefix * FIXME: check what happens with streams * @param string $zip_file * @param array $file_list * @param string $prefix Regular expression for the prefix to strip */ function zip_files_list($zip_file, $file_list, $prefix = '') { $archive = new ZipArchive(); $res = $archive->open(UploadFile::realpath($zip_file), ZipArchive::CREATE|ZipArchive::OVERWRITE); // we need realpath here for PHP streams support if ($res !== true) { $GLOBALS['log']->fatal("Unable to open zip file, check directory permissions: $zip_file"); return false; } foreach ($file_list as $file) { if (!empty($prefix) && preg_match($prefix, $file, $matches) > 0) { $zipname = substr($file, strlen($matches[0])); } else { $zipname = $file; } $archive->addFile($file, $zipname); } return true; }