Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "../include/session.php";
- if(isset($_POST['SubmitH'])){
- $aksi =isset($_GET['act'])?$_GET['act']:"";
- $id =isset($_GET['id'])?$_GET['id']:"";
- $TxtKodeH =(isset($_POST['TxtKodeH']))?$_POST['TxtKodeH']:"";
- $TxtJudul = $_POST['TxtJudul'];
- $TxtBerita = htmlentities((string)$_POST['TxtBerita']);
- $nama_file = $_FILES['file']['name'];
- $lokasi_file = $_FILES['file']['tmp_name'];
- $tipe_file = $_FILES['file']['type'];
- $size_file = $_FILES['file']['size'];
- $direktori = "../image/image_berita/$nama_file";
- $nama_file=!empty($lokasi_file)?$nama_file:'invalid.jpg';
- function cekDimensiMax($lokasi_file){
- $lebar_max = 1600;
- $tinggi_max = 1350;
- $hasil = 0;
- if(!empty($lokasi_file)){
- $ukuran_asli = getimagesize($lokasi_file);
- if ($ukuran_asli[0] > $lebar_max and $ukuran_asli[1] > $tinggi_max ) {
- $hasil = 1;
- }
- }
- return $hasil;
- }
- function cekInput($TxtJudul,$TxtBerita,$lokasi_file,$tipe_file,$size_file,$cekMax,$direktori){
- $msg='';
- if(empty($TxtJudul)){
- $msg.="<b>--> Judul Berita Belum Diisi <--</b>";
- }
- elseif(empty($TxtBerita)){
- $msg.="<b>--> Isi Berita Belum Diisi <--</b>";
- }
- else{
- if(!empty($lokasi_file)){
- if($tipe_file != "image/jpeg" and $tipe_file !="image/png"){
- $msg.="<b>Tipe Gambar Harus *.jpg atau *.png</b>";
- }
- elseif($size_file > 1000000){
- $msg.="<b>Max File 1 Mb</b>";
- }
- elseif($cekMax==1){
- $msg.="<b>Max Dimensi 1600 x 1350 pixel</b>";
- }else{
- move_uploaded_file($lokasi_file,$direktori);
- }
- }
- }
- return $msg;
- }
- // Panggil fungsi dimensi dan definisikan
- $cekMax = cekDimensiMax($lokasi_file);
- # aksi simpan berita
- if($aksi == "simpan"){
- $msg=cekInput($TxtJudul,$TxtBerita,$lokasi_file,$tipe_file,$size_file,$cekMax,$direktori);
- if(!empty($msg)){
- echo $msg;
- include "tambahBerita.php";
- }else{
- $sql = "INSERT INTO berita (judul,gambar,isi_berita,hari,tanggal,jam)
- VALUES ('$TxtJudul','$nama_file','$TxtBerita','$hari_ini','$tgl_sekarang','$jam_sekarang')";
- mysql_query($sql, $koneksi) or die("SQL Error !!".mysql_error());
- echo "<script>alert('Berita Berhasil Disimpan');window.location.href='login.php?hal=daftar-berita';</script>";
- }
- }
- # aksi edit berita
- if($aksi == "edit"){
- $msg=cekInput($TxtJudul,$TxtBerita,$lokasi_file,$tipe_file,$size_file,$cekMax,$direktori);
- if(!empty($msg)){
- echo $msg;
- include "editBerita.php";
- }else{
- $sql = "UPDATE berita SET judul='$TxtJudul',gambar='$nama_file',isi_berita='$TxtBerita',hari='$hari_ini',tanggal='$tgl_sekarang',jam='$jam_sekarang'
- WHERE id_berita='$TxtKodeH'";
- mysql_query($sql, $koneksi) or die("SQL Error !!".mysql_error());
- echo "<script>alert('Berita Berhasil Diubah');window.location.href='login.php?hal=daftar-berita';</script>";
- }
- }
- # aksi hapus berita
- if($aksi == "hapus"){
- $sql = "DELETE FROM berita WHERE id_berita='$id'";
- mysql_query($sql, $koneksi) or die("SQL Error !!".mysql_error());
- echo "<script>alert('Berita Berhasil Dihapus');window.location.href='login.php?hal=daftar-berita';</script>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement