View file download/zip.php

File size: 8.83Kb
<?php

require_once ( "../includes/start.php" );
require_once ( "../includes/functions.php" );
require_once ( "../includes/header.php" );
include_once ( "../themes/" . $config['themes'] . "/index.php" );

include_once "../includes/pclzip.php";

$dir = check( $_GET['dir'] );
$arch = check( $_GET['arch'] );
$open = check( $_GET['open'] );
if ( isset( $_GET['action'] ) )
		$action = check( $_GET['action'] );
if ( isset( $_GET['start'] ) )
		$start = ( int )$_GET['start'];

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

		show_title( 'partners.gif', 'Просмотр архива' );
		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>';

								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 '.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 '.exe':
														$ico = 'exe.gif';
														break;
												case '.htm':
														$ico = 'htm.gif';
														break;
												case '.html':
														$ico = 'htm.gif';
														break;
												case '.php':
														$ico = 'php.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/icons/' . $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" );

?>