Extract an archive file to a directory.
{
$untar = false;
$result = false;
{
$untar = true;
}
switch ($ext)
{
case 'zip':
if ($adapter)
{
$result = $adapter->extract($archivename, $extractdir);
}
break;
case 'tar':
if ($adapter)
{
$result = $adapter->extract($archivename, $extractdir);
}
break;
case 'tgz':
$untar = true;
case 'gz':
case 'gzip':
if ($adapter)
{
$tmpfname = $config->get('tmp_path') . '/' . uniqid('gzip');
$gzresult = $adapter->extract($archivename, $tmpfname);
if ($gzresult instanceof Exception)
{
@unlink($tmpfname);
return false;
}
if ($untar)
{
if ($tadapter)
{
$result = $tadapter->extract($tmpfname, $extractdir);
}
}
else
{
}
@unlink($tmpfname);
}
break;
case 'tbz2':
$untar = true;
case 'bz2':
case 'bzip2':
if ($adapter)
{
$tmpfname = $config->get('tmp_path') . '/' . uniqid('bzip2');
$bzresult = $adapter->extract($archivename, $tmpfname);
if ($bzresult instanceof Exception)
{
@unlink($tmpfname);
return false;
}
if ($untar)
{
if ($tadapter)
{
$result = $tadapter->extract($tmpfname, $extractdir);
}
}
else
{
}
@unlink($tmpfname);
}
break;
default:
throw new InvalidArgumentException('Unknown Archive Type');
}
if (!$result || $result instanceof Exception)
{
return false;
}
return true;
}