'clientFilename') * @param string $filesDir a path to the files on disk. * * @return string the path to the archive. */ public function create($files, $filesDir) { // Create a temporary file. $archivePath = tempnam('/tmp', 'sf-'); if ($archivePath === false) { return false; } unlink($archivePath); // attempt to use Zip first, if it is available. Otherwise // fall back to the tar CLI. $zipTest = false; if (self::zipFunctional()) { $zipTest = true; $zip = new ZipArchive(); if ($zip->open($archivePath, ZipArchive::CREATE) == true) { foreach ($files as $serverPath => $clientFilename) { $zip->addFile($filesDir . '/' . $serverPath, $clientFilename); } $zip->close(); } } elseif (self::tarFunctional()) { // Create the archive and download the file. exec( Config::getVar('cli', 'tar') . ' -c -z ' . '-f ' . escapeshellarg($archivePath) . ' ' . '-C ' . escapeshellarg($filesDir) . ' ' . implode(' ', array_map('escapeshellarg', array_keys($files))) ); } else { throw new Exception('No archive tool is available!'); } return $archivePath; } /** * Return true if the zip extension is loaded. * * @return bool */ public static function zipFunctional() { return (extension_loaded('zip')); } /** * Return true if the tar tools are configured. */ public static function tarFunctional() { $tarBinary = Config::getVar('cli', 'tar'); return !empty($tarBinary) && file_exists($tarBinary); } public static function isFunctional() { return self::zipFunctional() || self::tarFunctional(); } } if (!PKP_STRICT_MODE) { class_alias('\PKP\file\FileArchive', '\FileArchive'); }