function getArchiveTree($level = 1) { $tree = []; if (isset($_GET['path'])) { //TODO: Common::checkPath($path) return false... $source = getWorkspacePath($_GET['path']); //$source = WORKSPACE . "/" . $_GET['path']; if (file_exists($source)) { $source_info = pathinfo($source); if (isset($source_info['extension']) && !empty($source_info['extension'])) { $des = dirname($source); if ($source_info['extension'] == 'zip') { if (class_exists('ZipArchive') && ($zip = new ZipArchive())) { if ($res = $zip->open($source)) { for ($i = 0; $i < $zip->numFiles; $i++) { $name = $zip->getNameIndex($i); $path = $name; $count = substr_count($path, '/'); if ($count > $level) { continue; } $tree[$name] = $path; } $zip->close(); } } } elseif ($source_info['extension'] == 'tar') { if (class_exists('PharData') && ($tar = new PharData($source))) { //TODO: get tar tree } } elseif ($source_info['extension'] == 'rar') { if (class_exists('rar_open') && ($rar = new rar_open())) { if ($res = $rar->open($source)) { $entries = rar_list($res); //TODO: get rar tree $rar->close(); } } } } } } return $tree; }
if ($tar_bzip2_files = $bz->decompress()) { $tar_bzip2 = new PharData($tar_bzip2_files); if (${$tar_bzip2}->extractTo($des)) { echo '{"status":"success","message":"File extracted"}'; } else { echo '{"status":"error","message":"Failed to extract the files"}'; } } else { echo '{"status":"error","message":"Failed to extract the .bzip2 file"}'; } } else { echo '{"status":"error","message":"PharData extension missing or cloud not open tar archive"}'; } } elseif ($source_info['extension'] == 'rar') { if (class_exists('rar_open') && ($rar = new rar_open())) { if ($res = $rar->open($source)) { $entries = rar_list($res); try { foreach ($entries as $entry) { $entry->extract($des); } } catch (Exception $e) { $error = true; } // extract it to the path we determined above if ($error === false) { echo '{"status":"success","message":"File extracted"}'; } else { echo '{"status":"error","message":"Failed to extract contents"}'; } $rar->close();