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

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

if($filename==""){

}else{
    
    //
    //
	if(!in_array($ext,$allowed) ) {
		header("location:00_foto_baground.php?alert=gagal");
	}else{
	    if($ukuran < 5000000){
    		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/'.$kdc.'_'.$filename);
    		$x = $kdc.'_'.$filename;
    		mysqli_query($koneksi, "update kdkanca set foto_bag='$x' where kd='$kdc'");
    		header("location:00_foto_baground.php?alert=berhasil");
	    }else{
	        	header("location:00_foto_baground.php?alert=gagal"); 
	    }
	}
}







