-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathtambahdata.php
More file actions
62 lines (50 loc) · 1.76 KB
/
tambahdata.php
File metadata and controls
62 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
// membutuhkan pemanggilan akses koneksi (mysql)
require 'koneksi.php';
// menjalankan session
session_start();
// check apakah session email sudah ada atau belum.
// jika belum maka akan diredirect ke halaman index (login)
if( empty($_SESSION['uname']) ){
header('Location: login.html');
}
?>
<?php
// tambah data
if(isset($_POST['tambah'])){
$ekstensi_diperbolehkan = array('png','jpg', 'jpeg');
$urlgambar = $_FILES['file']['name'];
$x = explode('.', $urlgambar);
$ekstensi = strtolower(end($x));
$ukuran = $_FILES['file']['size'];
$file_tmp = $_FILES['file']['tmp_name'];
// mengambil data
$judul = mysqli_real_escape_string($db, $_POST['judul']);
$deskripsi = mysqli_real_escape_string($db, $_POST['deskripsi']);
//pengecekan gambar
if(in_array($ekstensi, $ekstensi_diperbolehkan) === true){
if($ukuran < 1222044070){
move_uploaded_file($file_tmp, 'img/'.$urlgambar);
//buat query
$sql = "INSERT INTO dataku (gambar, judul, deskripsi) VALUE ('$urlgambar', '$judul', '$deskripsi')";
// eksekusi query
$query = mysqli_query($db, $sql);
// jika berhasil ditambahkan
if($query){
?>
<script type="text/javascript">alert('Data Berhasil Ditambahkan!'); document.location.href='index.php';</script>
<?php
// jika gagal ditambahkan
}else{
?>
<script type="text/javascript">alert('Data Gagal Ditambahkan!'); document.location.href='index.php';</script>
<?php
}
}else{
echo 'UKURAN FILE TERLALU BESAR';
}
}else{
echo 'EKSTENSI FILE YANG DI UPLOAD TIDAK DI PERBOLEHKAN';
}
}
?>