/** * @param string The name of the archive * @param mixed The name of a single file or an array of files * @param string The compression for the archive * @param string Path to add within the archive * @param string Path to remove within the archive * @param boolean Automatically append the extension for the archive * @param boolean Remove for source files */ function create($archive, $files, $compress = 'tar', $addPath = '', $removePath, $autoExt = true) { $compress = strtolower($compress); if ($compress == 'tgz' || $compress == 'tbz' || $compress == 'tar') { require_once _EXT_PATH . '/libraries/Tar.php'; if (is_string($files)) { $files = array($files); } if ($autoExt) { $archive .= '.' . $compress; } if ($compress == 'tgz') { $compress = 'gz'; } if ($compress == 'tbz') { $compress = 'bz2'; } $tar = new Archive_Tar($archive, $compress); $tar->setErrorHandling(PEAR_ERROR_PRINT); $result = $tar->addModify($files, $addPath, $removePath); return $result; } elseif ($compress == 'zip') { $adapter =& xFileArchive::getAdapter('zip'); if ($adapter) { $result = $adapter->create($archive, $files, $removePath); } if ($result == false) { return PEAR::raiseError('Unrecoverable ZIP Error'); } } }
public function extract($mount, $what, &$errors) { $to = ''; $this->safeIniSet('memory_limit', '128M'); @set_time_limit(0); require_once realpath(dirname(__FILE__)) . "/Archive/archive.php"; $this->safeIniSet('memory_limit', '128M'); @set_time_limit(0); $archive = new xFileArchive(); $root = $this->toRealPath($mount); $firstItem = str_replace($mount, '', $what); $what = $root . DIRECTORY_SEPARATOR . $firstItem; $result = false; if (file_exists($what)) { $to = dirname($what); if (@is_writable($to)) { $result = $archive->extract($what, $to); } } xapp_clog('w ' . $result); return $result; /* if ($to == null || $to=='') { $firstItem = str_replace($mount,'',$firstItem); $to = $root . DIRECTORY_SEPARATOR . $firstItem . '.zip'; if(file_exists($to)){ $base = basename($to); $ext = ''; $dotPos = strrpos($base, "."); if ($dotPos > -1) { $radic = substr($base, 0, $dotPos); $ext = substr($base, $dotPos); } $i = 1; $newName = $base; while (file_exists($dstDirectory . "/" . $newName)) { $suffix = "-$i"; if (isSet($radic)) { $newName = $radic . $suffix . $ext; } else { $newName = $base . $suffix; } $i++; } $destFile = $dstDirectory . "/" . $newName; } } */ /*$archive->create($to, $zipSelection, 'zip', '', $root, true);*/ return $to; }