protected function _extract($path, $arc)
{
if ($this->quarantine) {
$dir = $this->quarantine . DIRECTORY_SEPARATOR . str_replace(' ', '_', microtime()) . basename($path);
$archive = $dir . DIRECTORY_SEPARATOR . basename($path);
if (!@mkdir($dir)) {
return false;
}
chmod($dir, 0777);
// copy in quarantine
if (!copy($path, $archive)) {
return false;
}
// extract in quarantine
$this->_unpack($archive, $arc);
unlink($archive);
// get files list
$ls = array();
foreach (scandir($dir) as $i => $name) {
if ($name != '.' && $name != '..') {
$ls[] = $name;
}
}
// no files - extract error ?
if (empty($ls)) {
return false;
}
$this->archiveSize = 0;
// find symlinks
$symlinks = $this->_findSymlinks($dir);
// remove arc copy
$this->remove($dir);
if ($symlinks) {
return $this->setError(elFinder::ERROR_ARC_SYMLINKS);
}
// check max files size
if ($this->options['maxArcFilesSize'] > 0 && $this->options['maxArcFilesSize'] < $this->archiveSize) {
return $this->setError(elFinder::ERROR_ARC_MAXSIZE);
}
// archive contains one item - extract in archive dir
if (count($ls) == 1) {
$this->_unpack($path, $arc);
$result = dirname($path) . DIRECTORY_SEPARATOR . $ls[0];
} else {
// for several files - create new directory
// create unique name for directory
$name = basename($path);
if (preg_match('/\\.((tar\\.(gz|bz|bz2|z|lzo))|cpio\\.gz|ps\\.gz|xcf\\.(gz|bz2)|[a-z0-9]{1,4})$/i', $name, $m)) {
$name = substr($name, 0, strlen($name) - strlen($m[0]));
}
$test = dirname($path) . DIRECTORY_SEPARATOR . $name;
if (file_exists($test) || is_link($test)) {
$name = $this->uniqueName(dirname($path), $name, '-', false);
}
$result = dirname($path) . DIRECTORY_SEPARATOR . $name;
$archive = $result . DIRECTORY_SEPARATOR . basename($path);
if (!$this->_mkdir(dirname($path), $name) || !copy($path, $archive)) {
return false;
}
$this->_unpack($archive, $arc);
@unlink($archive);
}
return file_exists($result) ? $result : false;
}
}