<?php
session_start();
include('connect.php');
$session_id=rand(0,999); // User session id
$path = "uploads/";
$idu = $_POST['idu'];
$ida = $_POST['ida'];
$type = $_POST['type'];
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST"){
	$name = $_FILES['photoimg']['name'];
	$size = $_FILES['photoimg']['size'];
	if(strlen($name)){
		list($txt, $ext) = explode(".", $name);
		if(in_array($ext,$valid_formats)){
			if($size<(1024*1024)){
				$actual_image_name = time().$session_id.".".$ext;
				$tmp = $_FILES['photoimg']['tmp_name'];
				if(move_uploaded_file($tmp, $path.$actual_image_name)){
					$insertor =@mysql_result(mysql_query("SELECT `value` FROM `settings` WHERE `type`='custom_logo'"),0,0);
					if($insertor){
					@unlink("uploads/$insertor");
						@mysql_query("UPDATE `settings` SET `value`='$actual_image_name' WHERE `type`='custom_logo'");
					}else{
						@mysql_query("INSERT INTO `settings`(`type`,`value`) VALUES('custom_logo','$actual_image_name')");	
					}
					echo "<img src=\"../uploads/$actual_image_name\"/>";
				}else{
					echo "Eroare la Upload";
				}
			}else{
				echo "Marimea maxima a fisierului este de 1MB";
			}
		}else{
			echo "Formatul imaginii trebuie sa fie jpg,png,gif,bmp,jpeg";
		}
	}else{
		echo "Selecteaza o imagine";
		exit;
	}
	
}
?>