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

$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/diri/".$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/diri/'.$kdc.'_'.$filename);
    		$x = $kdc.'_'.$filename;
    		mysqli_query($koneksi, "update anggota set foto_diri='$x' where angg_id='$id'");
    		header("location:angg_foto_diri.php?alert=berhasil");
	    }else{
	       	header("location:angg_foto_diri.php?alert=gagal"); 
	    }
	}
}







