Просмотр файла downs/zip.php

Размер файла: 2.67Kb
<?php

$title='Просмотр архива';
require"../system/config.php";
require"../system/func.php";
require"../system/head.php";
require"../system/error.php";
$pad=prov(base64_decode($_GET['arh'])); $path=pathinfo($pad);

if(!preg_match("/..\/down\/(.*?)\//i",$pad)){header("Location: index.php"); exit;}

echo'<div class="i" align="center">'.$title.' '.$path['basename'].'</div><br>';

function sizer($s)
{
$o=1;
while($s>1024){
$s=round($s/1024,1);
$o++;
}
switch($o){
case(1):
$o='b';
break;

case(2):
$o='Kb';
break;
case(3):
$o='Mb';
break;
case(4):
$o='Gb';
break;
}
return $s.$o;
}


if(!empty($_GET['arh']))
$arh = base64_decode($_GET['arh']);
if(!is_file($arh))
die('Файла не существует!');
if(!empty($_GET['act']))
$act = $_GET['act'];
else
$act = 'main';
$zip = new ZipArchive ();
if($zip-> open ($arh) === TRUE){
switch($act){
case('main'):
 echo'Обьектов: '.$zip->numFiles.'<br/>';
 if($zip->comment != NULL)
 echo'Комментарий: '.$zip->comment.'<br/>';
 for ($i = 0; $i < $zip->numFiles; $i++) {
 $t = $zip-> statIndex($i);
 if(preg_match('/\/$/',$t['name']))
 echo 'Каталог <strong>'.$t['name'].'</strong>';
 else
 echo '<a href="zip.php?act=pre&arh='.$_GET['arh'].'&index='.$t['index'].'">'.$t['name'].'</a> ['.sizer($t['size']).'/'.sizer($t['comp_size']).']';
 echo'<br/>';
 }

break;
case('pre'):
if($info = $zip->statIndex(abs((int)$_GET['index']))){
echo'Файл '.$info['name'].'<br/>
<a href="zip.php?act=down&arh='.$_GET['arh'].'&index='.$info['index'].'">Скачать файл</a>
<br/>
Вес запакованого файла '.sizer($info['comp_size']).' ('.$info['comp_size'].' b)<br/>
Вес распакованого файла: '.sizer($info['size']).' ('.$info['size'].' b)<br/>
Метод сжатия: '.$info['comp_method'].'<br/>';
$highlight=array('php','html','htm');
$astext=array('txt','css','ini','htaccess');
$type=substr($info['name'],strrpos($info['name'],'.')+1);
if(in_array($type, $highlight)){
highlight_string($zip->getFromIndex($info['index']));
}elseif(in_array($type, $astext)){
echo nl2br(htmlspecialchars($zip->getFromIndex($info['index'])));
}
}else{
echo 'Ошибка извлечения файла!';
}
break;
case('down'):
$index = abs((int)$_GET['index']);
if($name = $zip->getNameIndex($index)){
header('Content-Type: application/octet-stream', true);
header('Content-Disposition: attachment; filename="'.urlencode(basename($name)).'";');
echo $zip->getFromIndex($index);
}else{
echo 'Ошибка извлечения файла!';
}
break;
default:
echo'Не известное действие';
break;
}
$zip->close();
}else{
echo'Ошибка открытия архива!';
} require"../system/foot.php";
?>