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

Размер файла: 4.85Kb
<?php
define('SHCMS', true);
include_once'../system/inc/basic_settings.php';
$shcmsengine['title'] = 'Просмотр архива';


if (isset($_GET['id'])) {
	$id = abs(intval($_GET['id']));
} else {
	$id = 0;
} 
if (isset($_GET['start'])) {
	$start = abs(intval($_GET['start']));
} else {
	$start = 0;
} 


switch ($act)
{
	case '':
	include_once'../template/head.php';
$file_arhiv = mysql_fetch_array(mysql_query("SELECT * FROM `download_file` WHERE `id`='$id'"));

  /*
   Проверка на существования файла
  */
if (($file_arhiv == null) ||(!is_file('files_obmen/'.$file_arhiv['name']))) {
echo "<div class='errors'>Файл не найден или был удален.</div>";
    include_once'../template/foot.php';
    exit();}
  /*
   Объявляем клаcc PclZip
  */
$zip = new PclZip('files_obmen/'.$file_arhiv['name']);


if (($list = $zip->listContent()) == 0) {die("Возникла ошибка: " . $zip->errorInfo(true));}

for ($i = 0; $i < sizeof($list); $i++) {
for (reset($list[$i]); $key = key($list[$i]); next($list[$i])) {
$zipdirarhive = strstr($listcontent, "--size");
$zipdirarhive = ereg_replace("--size:", "", $zipdirarhive);
$zipdirarhive = @ ereg_replace("$zipdirarhive", "$zipdirarhive|", $zipdirarhive);
$sizelist .= "$zipdirarhive";
$listcontent = "[$i]--$key:" . $list[$i][$key] . "";
$arhive_list = strstr($listcontent, "--filename");
$arhive_list = ereg_replace("--filename:", "", $arhive_list);
$arhive_list = ereg_replace("$arhive_list", "$arhive_list|", $arhive_list);
$savelist .= "$arhive_list";
}
}
$sizefiles2 = explode("|", $sizelist);
$sizelist2 = array_sum($sizefiles2);
$obkb = round($sizelist2 / 1024, 2);

$preview = "$savelist";
$preview = explode("|", $preview);
$count = count($preview) - 1;
echo "<b>$arch</b>Файлов всего: $count<hr/>";
if (empty ($_GET['page'])) {
    $page = 1;
}
else {
    $page = intval($_GET['page']);
}
$start = $page * 10 - 10;
if ($count < $start + 10) {
    $end = $count;
}
else { $end = $start + 10;}
for ($i = $start; $i < $end; $i++) {
    $sizefiles = explode("|", $sizelist);
    $selectfile = explode("|", $savelist);
    $path = $selectfile[$i];
    $filename = ereg_replace(".*[\\/]", "", $path);
    $zdir = ereg_replace("[\\/]?[^\\/]*$", "", $path);
    $tfl = strtolower(size($filename));
  $arrext = array('.xml', '.wml', '.asp', '.aspx', '.shtml', '.htm', '.phtml', '.html', '.php', '.htt', '.dat', '.tpl', '.htaccess', '.pl', '.js', '.jsp', '.css', '.txt', '.sql', '.gif', '.png', '.bmp', '.wbmp', '.jpg', '.jpeg');

    if (in_array($tfl, $arrext)) {
        echo "$zdir/$filename";
    }
    else {
			echo '<b>'.$zdir.'/ </b><a href="zip.php?act=preview&amp;id='.$id.'&amp;view='.$i.'&amp;start='.$start.'&amp;">'.$filename.'</a>';//Выводит файлы
    }
    if ($sizefiles[$i] != "0") {
        $sizekb = round($sizefiles[$i] / 1024, 2);
        echo " ($sizekb кб)";
    }

    echo '<br/>';
}
		
		include_once'../template/foot.php';
	break;


case "preview":
include_once '../template/head.php';
$shcmsengine['title'] = 'Просмотр файлов';
		$view = abs(intval($_GET['view']));

$downs = mysql_fetch_array(mysql_query("SELECT * FROM `download_file` WHERE `id`='$id'"));
$shcmsengine['title'] = ''.$downs['names'].'';
		if ($downs > 0) {
			$zip = new PclZip('files_obmen/'.$downs['name']);

			$content = $zip -> extract(PCLZIP_OPT_BY_INDEX, $view, PCLZIP_OPT_EXTRACT_AS_STRING);
			if (!empty($content)) {
				$filecontent = $content[0]['content'];
				$filename = $content[0]['filename'];

				echo '<img src="icons/zip.png" alt="image" /> <b>'.$downs['name'].'</b><br /><br />';

				echo '<b>'.$filename.'</b> ('.size($content[0]['size']).')<hr />';

				if (!preg_match("/\.(gif|png|bmp|wbmp|jpg|jpeg)$/", $filename)) {
					if ($content[0]['size'] > 0) {
						if (utf($filecontent)) {
							echo '<div class="d">'.printCode($filecontent, 1).'</div><br />';
						} else {
							echo '<div class="d">'.printCode(win_utf8($filecontent), 1).'</div><br />';
						} 
					} else {
						echo 'Данный файл пустой!';
					} 
				} else {
					if (!empty($_GET['img'])) {
						$ext = strtolower(substr($filename, strrpos($filename, '.') + 1));

						ob_end_clean();
						ob_clean();

						header("Content-type: image/$ext");
						header("Content-Length: ".strlen($filecontent));
						header('Content-Disposition: inline; filename="'.$filename.'";');

						echo $filecontent;
						exit;
					} 

					echo '<img src="zip.php?act=preview&amp;id='.$id.'&amp;view='.$view.'&amp;img=1" alt="image" /><br /><br />';
				} 
			} else {
					echo'Ошибка! Не удалось извлечь файл!';
			} 
		} else {
				echo'Ошибка! Данного файла не существует!';
		} 

		echo ' <a href="zip.php?id='.$id.'&amp;start='.$start.'&amp;'.SID.'">Вернуться</a><br />';
        include_once'../template/foot.php';
	    break;
}


?>