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

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

if($filename==""){

}else{
    
    //
    //
	if(!in_array($ext,$allowed) ) {
		header("location:jaminan_bpkb_foto.php?alert=gagal");
	}else{
	    if($ukuran < 5000000){
    		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/tempus_1/'.$filename);
    		$x = $filename;
    		mysqli_query($koneksi, "update permohonan set foto_tempus_1='$x' where m_nomor='$id'");
    		header("location:jaminan_bpkb_foto.php?alert=berhasil");
	    }else{
	        	header("location:jaminan_bpkb_foto.php?alert=gagal"); 
	    }
	}
}







