<?php 
include '../koneksi.php';
$id     = $_POST['id'];
$id_kar = $_POST['id_kar'];
$nama   = $_POST['nama'];
$user   = $_POST['user'];
$foto_lama = $_POST['foto_lama'];

// cek gambar
$rand       = rand();
$allowed    = array('png','bmp','jpg','jpeg');
$filename   = basename($_FILES['foto']['name']);
$ukuran     = $_FILES['foto']['size'];
$ext        = pathinfo($filename, PATHINFO_EXTENSION);

    $xfoto_lama = "../gambar/karyawan/".$foto_lama ;
    
    if (file_exists($xfoto_lama)) { ;
        unlink($xfoto_lama) ;
        }        

if($filename==""){

	mysqli_query($koneksi, "update user set user_nama='$nama', user_username='$user' where user_id='$id'");
	header("location:index.php");

}else{
    //1 044 070
	if(!in_array($ext,$allowed) ) {
		header("location:index.php?alert=gagal");
	}else{
	    if($ukuran < 5000000){
    		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/karyawan/'.$filename);
    		$x = $filename;
    		mysqli_query($koneksi, "update user set user_nama='$nama', user_username='$user', user_foto='$x' where user_id='$id'");
    		mysqli_query($koneksi, "update karyawan_iden set foto='$x' where id='$id_kar'");
    		
    		header("location:index.php?alert=berhasil");
	    }else{
	        	header("location:index.php?alert=gagal"); 
	    }
	}
}







