View file down/zip.php

File size: 5.87Kb
<?php
require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"../template/functions.php";
require_once"../template/antidos.php";
require_once"../template/cookies.php";
require_once"../template/gzip.php";
require_once"../template/header.php";
require_once"../template/referer.php";
include_once"../themes/$config_themes/index.php";
include_once"../template/isset.php";

include_once"../template/pclzip.php";

$dir=check($_GET['dir']); 
$arch=check($_GET['arch']); 
$open=check($_GET['open']);

if(!eregi("[^a-z0-9_@+-]",$dir) && (!eregi("[^a-z0-9_@+.-]",$arch))){	

echo '<img src="../images/img/partners.gif" alt=""> <b>Просмотр архива</b><br><br>';
if($dir!="" && $arch!=""){
if (!$action){

$zip=new PclZip("$dir/$arch");
if (($list = $zip->listContent()) != 0){

sort($list);

$countlist = count($list);
$zfilename = array();
$zfilesize = array();
$zfolder = array();

for ($i=0; $i<$countlist; $i++){

$zfilename[]=$list[$i]['filename'];
$zfilesize[]=$list[$i]['size'];
$zfolder[]=$list[$i]['folder'];

}


$totalsize=array_sum($zfilesize);

$total = count($zfilename);
echo '<img src="../images/img/zip.gif" alt=""> <b>'.$arch.'</b><br><br>';
echo 'Всего файлов: '.$total.'<br>Вес распакованного архива: '.formatsize($totalsize).'<hr>';

$start = (int)$_GET['start'];
if($start < 0 || $start > $total){$start = 0;}
if ($total < $start + $config_ziplist){ $end = $total; }
else {$end = $start + $config_ziplist; }
for ($i = $start; $i < $end; $i++){

$ext=strtolower(strrchr($zfilename[$i], "."));

switch($ext){
case 'dir': $ico='dir.gif'; break;
case '.jpg': case '.jpeg': $ico='jpg.gif'; break;
case '.gif': $ico='gif.gif'; break;
case '.3gp': $ico='3gp.gif'; break;
case '.bmp': $ico='bmp.gif'; break;
case '.mid': $ico='mid.gif'; break;
case '.mp3': $ico='mp3.gif'; break;
case '.wav': case '.amr': $ico='wav.gif'; break;
case '.mmf': $ico='mmf.gif'; break;
case '.jad': $ico='jad.gif'; break;
case '.jar': $ico='jar.gif'; break;
case '.zip': $ico='zip.gif'; break;
case '.txt': $ico='txt.gif'; break;
case '.avi': $ico='avi.gif'; break;
case '.exe': $ico='exe.gif'; break;
case '.htm': $ico='htm.gif'; break;
case '.html': $ico='htm.gif'; break;
case '.php': $ico='php.gif'; break;
case '.css': $ico='css.gif'; break;
case '.dat': $ico='dat.gif'; break;
default: $ico='file.gif'; break; }

if($zfolder[$i]=="1"){
$zfilename[$i]=substr($zfilename[$i],0,-1);

echo '<img src="../images/icons/dir.gif" alt=""> <b>Директория '.$zfilename[$i].'</b><br>';
}else{
echo '<img src="../images/img/'.$ico.'" alt=""> <a href="zip.php?action=preview&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;open='.$zfilename[$i].'&amp;start='.$start.'&amp;'.SID.'">'.$zfilename[$i].'</a>';
echo ' ('.formatsize($zfilesize[$i]).')<br>'; 

}}

echo '<hr>';
if ($start != 0) {echo '<a href="zip.php?start='.($start - $config_ziplist).'&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;'.SID.'">&lt;-Назад</a> ';}else{echo'&lt;-Назад';}
echo ' | ';
if ($total > $start + $config_ziplist) {echo ' <a href="zip.php?start='.($start + $config_ziplist).'&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;'.SID.'">Далее-&gt;</a>';}else{echo'Далее-&gt;';}


if($total>0){

$ba=ceil($total/$config_ziplist);
$ba2=$ba*$config_ziplist-$config_ziplist;

echo '<br><hr>Страницы:';
$asd=$start-($config_ziplist*3);
$asd2=$start+($config_ziplist*4);

if($asd<$total && $asd>0){echo ' <a href="zip.php?start=0&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;'.SID.'">1</a> ... ';}
for($i=$asd; $i<$asd2;){

if($i<$total && $i>=0){
$ii=floor(1+$i/$config_ziplist);

if ($start==$i) {
echo ' <b>('.$ii.')</b>';
} else {
echo ' <a href="zip.php?start='.$i.'&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;'.SID.'">'.$ii.'</a> ';
}}

$i=$i+$config_ziplist;}
if($asd2<$total){echo ' ... <a href="zip.php?start='.$ba2.'&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;'.SID.'">'.$ba.'</a>';}
}

}else{
echo '<br><img src="../images/img/error.gif" alt=""> <b>Невозможно открыть архив!</b><br>';
echo 'Ошибка: '.$zip->errorInfo(true);
}

echo'<br><br><img src="../images/img/back.gif" alt=""> <a href="down.php?action=ob&amp;did='.$dir.'&amp;fid='.$arch.'&amp;'.SID.'">Вернуться</a><br>'; 
}
if($action=="preview"){
		
$zip=new PclZip("$dir/$arch");
$content = $zip->extract(PCLZIP_OPT_BY_NAME, $open,PCLZIP_OPT_EXTRACT_AS_STRING);
$content = $content[0]['content'];

$preview = explode("\r\n",$content);
$count = count($preview);
$ext = strtolower(substr($open, strrpos($open, '.') + 1));

echo '<img src="../images/img/zip.gif" alt=""> <b>'.$arch.'</b><br>';
echo '<img src="../images/img/files.gif" alt=""> <b>'.$open.'</b><br>';

if ($ext!="gif" && $ext!="jpg" && $ext!="png"){

echo 'Всего строчек: '.(int)$count.'<br><hr>';

if(is_utf($content)){echo highlight_code($content);}else{echo highlight_code(win_to_utf($content));}


}else{

if($create=="image"){
ob_end_clean();	
ob_clean();

header('Content-Disposition: attachment; filename="image.'.$ext.'";');
if($ext=="jpg"){$ext="jpeg";}
header("Content-type: image/$ext");
header("Content-Length: ".strlen($content));
echo $content;
exit;
}

echo'<br><img src="zip.php?action=preview&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;open='.$open.'&amp;create=image" alt="">'; 
}


echo'<hr><br><img src="../images/img/back.gif" alt=""> <a href="zip.php?start='.$start.'&amp;dir='.$dir.'&amp;arch='.$arch.'&amp;'.SID.'">Вернуться</a><br>'; 
}

}else{header ("Location: index.php?".SID); exit;}
}else{header ("Location: index.php?".SID); exit;}


echo'<img src="../images/img/dir.gif" alt=""> <a href="down.php?did='.$dir.'&amp;'.SID.'">В раздел</a><br>';	 
echo'<img src="../images/img/panel.gif" alt=""> <a href="index.php?'.SID.'">К категориям</a><br>';	
echo'<img src="../images/img/homepage.gif" alt=""> <a href="../index.php?'.SID.'">На главную</a>';
include_once"../themes/$config_themes/foot.php";
?>