ACC SHELL

Path : /srv/www/vhosts/petrikov/admin/pages/admin/
File Upload :
Current File : /srv/www/vhosts/petrikov/admin/pages/admin/images.php

<?php
	$make = select( "make", "view" );
	if ( $make == "view" )
	{
		$make = select( "do", "empty" );

		if ( $do != "empty" )
		{
			$file_source = select( "file", "" );

			if ( $file_source != "" )
			{
				$file = " <strong>\"". $file. "\"</strong>";
			}
			else
			{
				$file = "";
			}

			if ( $do == "saved" )
			{
				message( "Soubor$file byl úspěčně uložen." );
			}
			elseif ( $do == "deleted" )
			{
				if ( $file_source == "") {
					message( "Nebyl zadán soubor který chcete smazat." );
				} 
				else
				{
					unlink("../images/content/$file_source" );
					message( "Soubor$file byl úspěčně smazán." );
				}
			}
		}

		$files = scandir( '../images/content' );

		sort( $files );

		$j = -1;
		$table = array();

		for ( $i = 0; $i < count( $files ); $i++ ) {
			if ( preg_match( '/.*\.(GIF|JPG|JPEG|PNG)/', strtoupper( $files[ $i ] ), $finded ) ) {
				$j++;
				$table[ $j ][ 'name' ] = $files[ $i ];
			}
		}

		$smarty->assign( 'table', $table );

		$smarty->display( 'admin/images_view.tpl' );
	}
	elseif ( $make == "viewimg" )
	{
		$make = select( "file", "empty" );

		if ( file_exists( "../images/content/$file" ) ) {

			$info = getimagesize( "../images/content/$file" );

			$smarty->assign( 'width', $info[ 0 ] );

			$smarty->assign( 'height', $info[ 1 ] );

			$smarty->assign( 'file', $file );

			$smarty->assign( 'size', filesize( "../images/content/$file" ) );

			$smarty->display( 'admin/images_qview.tpl' );
		}
		else
		{
			message( "Zadaný soubor nebyl nalezen." );
		}
	}
	elseif ( $make == "add" )
	{
		if ( isset( $_POST[ "submit" ] ) )
		{
			

			$correct = TRUE;
			$message = "";

			if ( empty( $_FILES[ 'file' ][ 'name' ] ) ) {
				$correct = FALSE;
				$message .= "<p>Nebyl zadán soubor!</p>\n";
			}


			if ( !preg_match( '/.*\.(GIF|JPG|JPEG|PNG)/', strtoupper( $_FILES[ 'file' ][ 'name' ] ), $finded ) && $correct == TRUE) {
				$correct = FALSE;
				$message .= "<p>Zadaný soubor (".$_FILES[ 'file' ][ 'name' ].") není obrázek!</p>\n";
			}

			if ( file_exists( "../images/content/". $_FILES[ 'file' ][ 'name' ] ) ) {
				$correct = FALSE;
				$message .= "<p>Zadaný soubor (".$_FILES[ 'file' ][ 'name' ].") již existuje!</p>\n";
			}			
			if ( $correct ) {
			  move_uploaded_file( $_FILES[ 'file' ][ 'tmp_name' ], '../images/content/'. $_FILES[ 'file' ][ 'name' ] );
			   
			  $info = getimagesize( "../images/content/".$_FILES[ 'file' ][ 'name' ] );
        $width = $width_old = $info[ 0 ];
        $height = $height_old = $info[ 1 ];
        
        if ( $width > 640 || $height > 480 ) {
        
        if ( $width_old > 640 ) {
          $height = $height - (($width_old-640)/($width_old/100))*($height_old/100);
          $width = 640;
        } 
        
        if ( $height > 480 ) {
          $width = $width - (($height-640)/($height/100))*($width/100);
          $height = 480;
        } 
        
        switch ($info[ 2 ]) {
          case 1: $img = imagecreatefromgif('../images/content/'. $_FILES[ 'file' ][ 'name' ]); break;
          case 2: $img = imagecreatefromjpeg('../images/content/'. $_FILES[ 'file' ][ 'name' ]); break;
          case 3: $img = imagecreatefrompng('../images/content/'. $_FILES[ 'file' ][ 'name' ]); break;
          default: return false;
        }
        $img2 = imagecreatetruecolor($width, $height);
        imagecopyresampled($img2, $img, 0, 0, 0, 0, $width, $height, $width_old, $height_old);
        switch ($info[ 2 ]) {
          case 1: $img = imagegif($img2, '../images/content/'. $_FILES[ 'file' ][ 'name' ]); break;
          case 2: $img = imagejpeg($img2, '../images/content/'. $_FILES[ 'file' ][ 'name' ]); break;
          case 3: $img = imagepng($img2, '../images/content/'. $_FILES[ 'file' ][ 'name' ]); break;
          default: return false;
        }        
				header ( "Location: index.php?action=images&make=view&do=saved&file=". $_FILES[ 'file' ][ 'name' ] );
			} else {
				
			}
		} else {
		echo "\n". $message. "<p>Zkuste to znovu...</p>\n";
		}
		}

		$smarty->display( 'admin/images_add.tpl' );
	}
	elseif ( $make == "del" )
	{
		$file = select( "name", "empty" );
		
		if ( $file != "empty" )
		{
			if ( file_exists( "../images/content/$file") )
			{
				$smarty->assign( 'file', $file );
				$smarty->display( 'admin/images_del.tpl' );
			}
			else
			{
				message( "Položka kterou chcete smazat neexistuje." );
			}
		}
		else
		{
			message( "Nebyl zadán název položky kterou chcete smazat." );
		}
	}
	else
	{
		message( "action_not_exist", TRUE );;
	}
?>	

ACC SHELL 2018