-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit.php
More file actions
96 lines (78 loc) · 2.59 KB
/
Copy pathsubmit.php
File metadata and controls
96 lines (78 loc) · 2.59 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
// You need to add server side validation and better error handling here
session_start();
include("administrator/includes/connection.php");
include("administrator/includes/function.php");
$data = array();
$keyInsert = '';
if ($_GET['key'] == 'foto') {
$keyInsert = 1;
}else if ($_GET['key'] == 'ijazah') {
$keyInsert = 2;
}else if ($_GET['key'] == 'transkrip') {
$keyInsert = 3;
}else if ($_GET['key'] == 'referensi') {
$keyInsert = 4;
}
if($_GET['status'] == 'reg')
{
$error = false;
$files = array();
$uploaddir = "img/pelamar/". $_SESSION["pelamarID"]."/";
if (!file_exists($uploaddir)) {
mkdir($uploaddir, 0777, true);
}
$sqlPrivate = "SELECT * FROM tb_lampiran WHERE id_pelamar='".$_SESSION["pelamarID"]."' AND type = '".$keyInsert."'";
$queryPrivate = mysql_query($sqlPrivate);
$countPrivate = mysql_num_rows($queryPrivate);
if ($countPrivate>0) {
$resultPrivate = mysql_fetch_array($queryPrivate);
$file = basename($resultPrivate['dir_file']);
// unlink($file);
if (!unlink($resultPrivate['dir_file'])){
$error = true;
}
}
foreach($_FILES as $file)
{
$target_file = $uploaddir . basename($file["name"]);
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Allow certain file formats
if($imageFileType != "pdf" &&
$imageFileType != "jpg" &&
$imageFileType != "jpeg"&&
$imageFileType != "png" &&
$imageFileType != "bmp" &&
$imageFileType != "gif" &&
$imageFileType != "xls" &&
$imageFileType != "xlsx"&&
$imageFileType != "doc" &&
$imageFileType != "docx") {
$error = true;
}
if(move_uploaded_file($file['tmp_name'], $uploaddir . $file["name"]))
{
$files[] = $uploaddir . $file["name"];
$sqlSelect = "SELECT * FROM tb_lampiran WHERE id_pelamar='".$_SESSION["pelamarID"]."' AND type = '".$keyInsert."'";
$querySelect = mysql_query($sqlSelect);
if (mysql_num_rows($querySelect)<=0) {
$sql = "INSERT INTO tb_lampiran (id_pelamar, type, dir_file)
VALUES ('".$_SESSION["pelamarID"]."', '".$keyInsert."', '".$uploaddir.$file["name"]."')";
}else{
$sql = "UPDATE tb_lampiran SET dir_file = '".$uploaddir.$file["name"]."' WHERE id_pelamar = '".$_SESSION["pelamarID"]."' AND type = '".$keyInsert."'";
}
$query = mysql_query($sql);
}
else
{
$error = true;
}
}
$data = ($error) ? array('error' => 'There was an error uploading your files') : array('files' => $files);
}
else
{
$data = array('success' => 'Lampiran telah diganti', 'formData' => $_POST);
}
echo json_encode($data);
?>