<?php
include"../../../../inc/conn.php";

// CEK HAK AKSES DISINI


$target_dir_foto    = "../../../../assets/materi/";
$target_file_foto   = $target_dir_foto . basename($_FILES["file"]["name"]);
$imageFileTypeFoto  = pathinfo($target_file_foto,PATHINFO_EXTENSION);
$namafile 			= date('Ymds').".".$imageFileTypeFoto;

$id_unit		= str_replace("'","`",(isset($_POST['id_unit'])) ? $_POST['id_unit'] : "");
$judul_materi	= str_replace("'","`",(isset($_POST['judul_materi'])) ? $_POST['judul_materi'] : "");

$simpan = mysqli_query($connect,"insert into tb_materi set 

		id_unit			= '".$id_unit."',
		judul_materi	= '".$judul_materi."',
		file 			= '".$namafile."'

")or die(mysqli_error($connect));


if($simpan){
	move_uploaded_file($_FILES['file']['tmp_name'],"../../../../assets/materi/$namafile");
	echo"<script>alert('File Artikel berhasil disimpan !');</script>";
	echo"<script>document.location.href='index.php?prefix=artikel&unit=$id_unit'</script>";
}else{
	echo"<script>alert('Gagal mengeksekusi perintah ini !');history.go(-1)</script>";
}
?>