-
Notifications
You must be signed in to change notification settings - Fork 0
/
quality_upload.php
71 lines (61 loc) · 2.27 KB
/
quality_upload.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
67
68
69
70
71
<?php
session_start();
ob_start(); // Start output buffering
if (!isset($_SESSION['id'])) {
header('location: index.php');
exit(); // Ensure the rest of the script doesn't execute
}
include('connection/connection.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Title Here</title>
<!-- Include SweetAlert2 library via CDN -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10/dist/sweetalert2.min.js"></script>
</head>
<body>
<?php
if (isset($_POST['submit'])) {
$title = $_POST['title'];
$target = "uploads/";
$user = $_SESSION['username'];
$targetDir = $target . "quality/";
$targetFile = $targetDir . basename($_FILES["file"]["name"]);
$fileType = $_FILES['file']['type'];
if ($fileType !== 'application/pdf') {
echo "<script>
Swal.fire({
icon: 'error',
title: 'Oops...',
text: 'Only PDFs are allowed.'
}).then((result) => {
if (result.isConfirmed) {
window.history.back();
}
});
</script>";
} else {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) {
$filename = $_FILES["file"]["name"];
$folder_path = $targetDir;
$time_stamp = date('Y-m-d H:i:s');
$sql = "INSERT INTO quality (title, filename, folder_path, time_stamp, uploaded_by) VALUES ('$title','$filename', '$folder_path','$time_stamp','$user')";
$result = mysqli_query($conn, $sql);
if ($result) {
// Set a session variable to indicate success
$_SESSION['upload'] = true;
}
header('location: quality.php');
}
}
}
?>
<?php
ob_end_flush(); // End output buffering and send contents to browser
?>
</body>
</html>