-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate.php
42 lines (39 loc) · 1.36 KB
/
validate.php
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
<?php
//panggil file config.php untuk menghubung ke server
include('config.php');
$bagian = $_POST['bagian'];
$nik = $_POST['nik'];
$nama = $_POST['nama'];
$email = $_POST['email'];
$tlp = $_POST['tlp'];
$ekstensi_diperbolehkan = array('pdf');
$namafile = $_FILES['fileupload']['name'];
$x = explode('.', $namafile);
$ekstensi = strtolower(end($x));
$ukuran = $_FILES['fileupload']['size'];
$file_tmp = $_FILES['fileupload']['tmp_name'];
$q = mysqli_query($connect, "SELECT * FROM applicants WHERE nik='$nik'");
if(mysqli_num_rows($q) >= 1){
header('location:index.php?message=duplicate');
return false;
}else if(in_array($ekstensi, $ekstensi_diperbolehkan) === true){
if($ukuran < 5044070){
$lokasi = 'files/'.$bagian.'-'.$nama.'.'.$ekstensi;
move_uploaded_file($file_tmp,$lokasi);
$query = mysqli_query($connect,"INSERT INTO applicants VALUES(NULL,'$nik', '$bagian', '$nama', '$email', '$tlp', '$lokasi','0',NULL,now(),NULL)");
if($query){
header('location:index.php?message=success');
return false;
}else{
header('location:index.php?message=gagal');
return false;
}
}else{
header('location:index.php?error=1');
return false;
}
}else{
header('location:index.php?error=2');
return false;
}
?>