<?php
if(isset($_POST['upload'])) {

	if (isset($_FILES['my_foto']) && ($_FILES['my_foto']['name'] != "")) {
	      		  
	  $imageinfo = getimagesize($_FILES['my_foto']['tmp_name']);
	  
    if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/png') {
      $error = "false_typ";
    } else {
      if ($imageinfo['mime'] == 'image/gif') {$typ='gif';}
      elseif ($imageinfo['mime'] == 'image/jpeg') {$typ='jpeg';}
      elseif ($imageinfo['mime'] == 'image/png') {$typ='png';}
			if ($_FILES['my_foto']['error'] == UPLOAD_ERR_OK) {
				if (is_uploaded_file($_FILES['my_foto']['tmp_name'])) {
				  $novy_nazov = 'obrazky/users/'.$_SESSION['id'].'.'.$typ;
				  $podarilosa = move_uploaded_file($_FILES['my_foto']['tmp_name'], $novy_nazov);
				  chmod($novy_nazov, 0777);
					if ($podarilosa) {
					 $error = "ok";
					 $zapis = true;
					 uploadni_to($typ);
					} else {
					 $error = "error";
					 $zapis = false;
					}
				}
			 } else { 
			   // nastane, ak bol uploadovaný súbor väcší ako upload_max_filesize (chyba 2)
			   // nastane aj vtedy, ak bol uploadovaný súbor väcší ako post_max_size (chyba 2)
			   	$error = $_FILES['foto'.$i]['error'] ;
		      	$zapis = false;
			 }
			 
		}
  }
}
?>
<form enctype="multipart/form-data" action="" method="post" name="form">
	<hr />Upload fotky: <br/><input class="input" type="file" name="my_foto" /> <small>(veľkosť súboru max. 2MB)</small>
	<br /><br /><input class="change_butt" type="submit" name="upload" value="Uložiť fotografiu" /><hr />
</form>