<?php
	session_start();
	include("config.php");
	$judul=mysqli_real_escape_string($mysqli,$_POST["txtJudul"]);
	$ringkasan=mysqli_real_escape_string($mysqli,$_POST["txtRingkasan"]);
	$srcfoto=$_FILES["txtFoto"]["tmp_name"];
	$nmfoto=strtolower(str_replace(" ", "_", $judul));
	$tanggal=date("Y-m-d H:i:s");
	
	if(!empty($srcfoto)){
		if($_FILES["txtFoto"]["type"]=="image/jpeg" || $_FILES["txtFoto"]["type"]=="image/png" || $_FILES["txtFoto"]["type"]=="image/gif"){
			if($_FILES["txtFoto"]["type"]=="image/jpeg"){
				$ext=".jpg";
			}elseif($_FILES["txtFoto"]["type"]=="image/png"){
				$ext=".png";
			}elseif($_FILES["txtFoto"]["type"]=="image/gif"){
				$ext=".gif";
			}
			$nmfoto=$nmfoto . $ext;
			move_uploaded_file($srcfoto, "../foto_berita/$nmfoto");
		}else{
			msgbox("Error: Format file gambar harus: JPG, PNG atau GIF.");
			echo "<script language='javascript'>
					history.back();
				  </script>";
			die();
		}
	}

	$sql="INSERT INTO m_gallery VALUES (null, '$nmfoto', '$judul', '$ringkasan',null)";
	
	$qry=mysqli_query($mysqli,$sql);
	
	if($qry){
	
		msgbox("Album berhasil dibuat...");
		lempar("admin.php?page=ls_album&page_desc=Daftar Album");
	}else{
		
		msgbox("Error: ".mysqli_error($mysqli));
		lempar("admin.php?page=ls_album&page_desc=Daftar Album");
	}
?>