All pastes #258277 Raw Edit

Something

public text v1 · immutable
#258277 ·published 2006-11-26 10:37 UTC
rendered paste body
<?php

class system {

	public $obsah = array();

	public function __construct()
	{
    session_start();
    
		global $slozka, $adresa;
		
    if (array_key_exists('akce', $_GET) == true)
		{
			switch ($_GET['akce'])
			{
				case 'upload':
					$this -> nahraj_soubor();
				break;
				default:
					$this -> uvod();
				break;
			};
		}
		elseif (array_key_exists('soubor', $_GET) == true)
		{
			$this -> stahni_soubor(); 
		}
		else
		{ 
			$this -> uvod(); 
		};	
	}

	public function nahraj_soubor()
	{
	
		global $slozka, $adresa;
	
		if (is_dir('./'. $slozka))
		{
			if (is_file('./'. $slozka .'/'.$_FILES['soubor']['name']) == false)
			{
			  if (move_uploaded_file($_FILES['soubor']['tmp_name'], './'. $slozka .'/'. $_FILES['soubor']['name'])) 
			  { 
					$_SESSION['info'] = 'Soubor byl uspesne nahran :-)';
					$this -> presmeruj($adresa);
			  }; 			
			}
			else
			{
				$_SESSION['info'] = 'Po&#382;adovaný soubor tu u&#382; MÁME!, máte sm&#367;lu :-P';
				$this -> presmeruj($adresa);			
			};
		};
	}

	public function vypis_seznam()
	{
	
		global $slozka, $adresa;
	
		$handle = opendir($slozka); 
		while ($file = readdir($handle))
		{
			if ($file != '.' && $file != '..' && $file != '.htaccess')
			{
				$this -> obsah[] = '<a href="'. $adresa .'/?soubor='. $file .'">'. $file .'</a><br>';
			};
		}
		closedir($handle);
	}
	
	public function stahni_soubor()
	{
	
		global $slozka, $adresa;
	
		if (is_file('./'.$slozka.'/'.$_GET['soubor']) == true)
		{
			$soubor = './'.$slozka.'/'.$_GET['soubor'];

			header('Content-Description: File Transfer'); 
			header('Content-Type: application/force-download'); 
			header('Content-Disposition: attachment; filename="'.$_GET['soubor'].'"'); 
			
			readfile ($soubor);
		
		}
		else
		{ 
			$_SESSION['info'] = 'Po&#382;adovaný soubor tu nemáme, máte sm&#367;lu :-P';
			$this -> presmeruj($adresa);
		};
	
	}

	public function vypis_informace()
	{
		if(isset($_SESSION['info']))
		{
			$this -> obsah .= $_SESSION['info'];
			unset($_SESSION['info']);
		};
	}
	
	public function upload_formular()
	{
		global $slozka, $adresa;	

		$this -> obsah .=
		'Nahrání souboru na server 
    <form method="POST" ENCTYPE="multipart/form-data" action="' .$adresa. '/?akce=upload"> 

        <input type="file" name="soubor">
				<input type="submit" value="Odeslat">

    </form>';
	}
	
	public function uvod()
	{
		$this -> upload_formular();
		$this -> vypis_informace();
		$this -> vypis_seznam();
	}
	
	public function presmeruj($kam)
	{
		header ('Location: '.$kam);
		exit;
	}

};


?>