<?php 
include '../koneksi.php';
$id  = $_POST['id'];
$kdc = $_SESSION['kdc'];

$foto_lama = $_POST['foto_kk_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/kk/".$foto_lama ;
    
    if (file_exists($xfoto_lama)) { ;
        unlink($xfoto_lama) ;
        }        

if($filename==""){

}else{
    
    //
    //
	if(!in_array($ext,$allowed) ) {
		header("location:angg_foto_tampil.php?alert=gagal");
	}else{
	    if($ukuran < 5000000){
    		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/kk/'.$kdc.'_'.$filename);
    		$x = $kdc.'_'.$filename;
    		mysqli_query($koneksi, "update anggota set foto_kk='$x' where angg_id='$id'");
    		header("location:angg_foto_kk.php?id=$id ");
	    }else{
	        	header("location:angg_foto_kk.php?id=$id "); 
	    }
	}
}







