<?php 
include '../koneksi.php';
$nama  = $_POST['nama'];
$nip = $_POST['nip'];
$username = $_POST['username'];
$password = md5($_POST['password']);

$rand = rand();
$allowed =  array('gif','png','jpg','jpeg');
$filename = $_FILES['foto']['name'];

if($filename == ""){
	mysqli_query($koneksi, "insert into guru values (NULL,'$nama','$nip','$username','$password','')");
	header("location:guru.php");
}else{
	$ext = pathinfo($filename, PATHINFO_EXTENSION);

	if(!in_array($ext,$allowed) ) {
		header("location:guru.php?alert=gagal");
	}else{
		move_uploaded_file($_FILES['foto']['tmp_name'], '../gambar/guru/'.$rand.'_'.$filename);
		$file_gambar = $rand.'_'.$filename;
		mysqli_query($koneksi, "insert into guru values (NULL,'$nama','$nip','$username','$password','$file_gambar')");
		header("location:guru.php");
	}
}

