-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument_upload.php
More file actions
50 lines (38 loc) · 1.5 KB
/
document_upload.php
File metadata and controls
50 lines (38 loc) · 1.5 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
<?php include 'inc/header1.php' ?>
Έγγραφα μαθήματος
<?php include 'inc/header2.php' ?>
<div class="container">
<?php
$title = $description = '';
$titleErr = $descriptionErr = '';
$targetDir = "files/documents/";
$fileName = basename($_FILES['file']['name']);
$targetFilePath = $targetDir . $fileName;
$fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);
if (isset($_POST['submit']) && !empty($_FILES['file']['name'])) {
if (empty($_POST['title'])) {
$titleErr = 'Γράψτε τον τίτλο';
} else {
$title = filter_input(INPUT_POST, 'title', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}
if (empty($_POST['description'])) {
$descriptionErr = 'Γράψτε την περιγραφή';
} else {
$description = filter_input(INPUT_POST, 'description', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}
if (empty($titleErr && $descriptionErr)) {
//add to database
move_uploaded_file($_FILES['file']['name'], $targetFilePath);
$sql = "INSERT INTO documents (title, description, location) VALUES ('$title', '$description', '$targetFilePath')";
if (mysqli_query($conn, $sql)) {
//success
header('Location: documents_tutor.php');
} else {
//error
echo 'Error: ' . mysqli_error($conn);
}
}
}
?>
</div>
<?php include 'inc/footer.php' ?>