<?php include('casa/setup.casa.php');
	$codigo = DataForms::POST('us_codigo');

	$NombreFoto = $_FILES['Foto']['name'];
	$temp = $_FILES['Foto']['tmp_name'];

	if(trim($NombreFoto)==''){				
		$html="<script>history.back();</script>";	  
	   echo $html;
		exit();
	}
//Actualizar foto
$folder = 'perfil/';
		$FotoNew = $codigo.substr(uniqid(),1,5);
		move_uploaded_file($temp, $folder.$FotoNew);	
		//redimensionar foto tamaño
		$thumb  = new Thumb();
		$thumb->loadImage($folder.$FotoNew); 					
		$thumb->resize(600,"width");  
      $thumb->save($folder.$FotoNew, 100);
      $thumb->resize(300,"width");  
		$thumb->save($folder.'small_'.$FotoNew, 100);

$sql = "UPDATE rol_usuarios SET
	us_foto = '$FotoNew'
WHERE us_codigo = '$codigo';";	

$db = new DB();
$db->dbSQL($sql);

$html="<script>self.location='".PATH_HOME."us-perfil/ver';</script>";	  
echo $html;
?>