-
Notifications
You must be signed in to change notification settings - Fork 17
/
simpantugas.php
66 lines (63 loc) · 1.84 KB
/
simpantugas.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require("config/config.default.php");
require("config/config.function.php");
require("config/functions.crud.php");
if(!isset($_SESSION['id_siswa'])){
header('location:logout.php');
}else{
$id_tugas = $_POST['id_tugas'];
$id_siswa = $_SESSION['id_siswa'];
$jawaban = addslashes($_POST['jawaban']);
$datetime = date('Y-m-d H:i:s');
$ektensi = ['jpg', 'png', 'docx', 'pdf', 'xlsx'];
if ($_FILES['file']['name'] <> '') {
$file = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
$ext = explode('.', $file);
$ext = end($ext);
if (in_array($ext, $ektensi)) {
$dest = 'tugas/';
$file = $id_tugas . '_' . $id_siswa . '.' . $ext;
$path = $dest . $file;
$upload = move_uploaded_file($temp, $path);
if ($upload) {
$data = array(
'id_tugas' => $id_tugas,
'id_siswa' => $id_siswa,
'jawaban' => $jawaban,
'file' => $file
);
$where = array(
'id_siswa' => $id_siswa,
'id_tugas' => $id_tugas
);
$cek = rowcount($koneksi, 'jawaban_tugas', $where);
if ($cek == 0) {
insert($koneksi, 'jawaban_tugas', $data);
} else {
update($koneksi, 'jawaban_tugas', $data, $where);
}
echo "ok";
} else {
echo "gagal";
}
}
} else {
$data = array(
'id_tugas' => $id_tugas,
'id_siswa' => $id_siswa,
'jawaban' => $jawaban
);
$where = array(
'id_siswa' => $id_siswa,
'id_tugas' => $id_tugas
);
$cek = rowcount($koneksi, 'jawaban_tugas', $where);
if ($cek == 0) {
insert($koneksi, 'jawaban_tugas', $data);
} else {
update($koneksi, 'jawaban_tugas', $data, $where);
}
echo "ok";
}
}