-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_document_submit.php
More file actions
43 lines (32 loc) · 1.32 KB
/
add_document_submit.php
File metadata and controls
43 lines (32 loc) · 1.32 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
<?php
session_start();
include 'db_connect.php';
// Έλεγχος αν ο χρήστης έχει ρόλο Tutor
if (!isset($_SESSION["role"]) || $_SESSION["role"] !== "Tutor") {
exit("Δεν έχετε δικαίωμα πρόσβασης.");
}
// ελεγχος αν ελαβε τα απαραιτητα πεδια
if (!isset($_POST["title"], $_POST["description"]) || !isset($_FILES["file"])) {
exit("Λείπουν δεδομένα.");
}
$title = trim($_POST["title"]);
$description = trim($_POST["description"]);
if ($_FILES["file"]["error"] !== UPLOAD_ERR_OK) {
exit("Σφάλμα στο ανέβασμα του αρχείου.");
}
$uploadDir = "uploads/";
$originalName = basename($_FILES["file"]["name"]);
$uniqueName = uniqid() . "_" . $originalName;
$targetPath = $uploadDir . $uniqueName;
if (!move_uploaded_file($_FILES["file"]["tmp_name"], $targetPath)) {
exit("Αποτυχία μεταφοράς του αρχείου στον server.");
}
$stmt = $conn->prepare("INSERT INTO documents (title, description, link) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $title, $description, $uniqueName);
if ($stmt->execute()) {
echo "Το έγγραφο προστέθηκε επιτυχώς!";
} else {
echo "Σφάλμα κατά την εισαγωγή: " . $stmt->error;
}
$stmt->close();
$conn->close();