<?php
if(file_exists($_FILES['logo']['tmp_name']) && is_uploaded_file($_FILES['logo']['tmp_name'])) {
		
	$file_data = $_FILES['logo']['tmp_name'];
	$file_name = $_FILES['logo']['name'];
	$file_type = $_FILES['logo']['type'];
			
	$extension_tmp = explode(".", $file_name);
	$extension = end($extension_tmp);
	
	$extension_new = mime2ext($file_type, $extension);
	
	$file_new = "logo.".$extension_new;
	$file_dir = "images/";
		
	$sql_tmp = "SELECT value FROM ".$module." WHERE title = 'logo' ";
	$result_tmp = $conn->prepare($sql_tmp);
	$result_tmp->execute();
	if ($result_tmp->rowCount()){
		$arr_tmp = $result_tmp->fetch();
		if (is_file($file_dir.$arr_tmp['value'])) unlink($file_dir.$arr_tmp['value']);
	  $sql = "UPDATE ".$module." SET value = :value, c_public = '0' WHERE title = 'logo'";
		$result = $conn->prepare($sql);
		$result->bindValue(':value', $file_new, PDO::PARAM_STR);
		$result->execute();
	} else {
		if (is_file($file_dir."logo.png")) unlink($file_dir."logo.png");
	  $sql = "INSERT INTO ".$module." SET value = :value, title = 'logo', c_public = '0' ";
		$result = $conn->prepare($sql);
		$result->bindValue(':value', $file_new, PDO::PARAM_STR);
		$result->execute();
	}
	
	copy($file_data, $file_dir.'tmp_'.$file_new);
	resize($file_dir.'tmp_'.$file_new, $file_dir.$file_new, '197', '60');
	unlink($file_dir.'tmp_'.$file_new);
	chmod($file_dir.$file_new, 0644);
}