-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_upload_file.php
133 lines (108 loc) · 3.06 KB
/
admin_upload_file.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
include 'connect.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Untuk Bersihin Input
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
// Count total files
$countfiles = count($_FILES['files']['name']);
// Prepared statement
$query = "INSERT INTO content (original_name , path , isActive, createdAt, createdBy)
VALUES(?, ?, 1, NOW(), ?)";
$statement = $pdo->prepare($query);
$createdBy = $_SESSION['email'];
// Loop all files
for ($i = 0; $i < $countfiles; $i++) {
// File name
$filename = test_input($_FILES['files']['name'][$i]);
// file extension and lower extension name
$file_extension = strtolower(pathinfo(
$filename,
PATHINFO_EXTENSION
));
// Valid image extension
$valid_extension = array("png", "jpeg", "jpg", "mp4");
if (in_array($file_extension, $valid_extension)) {
// File Location Destination
$target_file = 'uploaded_files/' . hash("sha256", $filename) . '.' . $file_extension;
// Upload file
if (copy($_FILES['files']['tmp_name'][$i], $target_file)) {
// Execute query
$statement->execute(array($filename, $target_file, $createdBy));
}
}
}
header('Location: admin_home.php?stat=1');
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, Helvetica, sans-serif;
}
@import url('https://fonts.googleapis.com/css?family=Playfair+Display|Roboto');
#drop-area {
background:#f6f9ff;
border: 4px dashed lightblue;
border-radius: 30px;
width: 50%;
font-family: sans-serif;
margin: 5% auto;
padding: 0%;
}
#drop-area.highlight {
border-color: purple;
}
p {
margin-top: 0;
text-align: center;
font-size: 2em;
font-family: 'Playfair Display', serif;
}
.button {
display: inline-block;
padding: 10px;
margin: 0 22%;
background: pink;
cursor: pointer;
border-radius: 5px;
border: 1px solid pink;
font-family: 'Roboto', serif;
}
.button:hover {
background: aquamarine;
color: #aaa;
font-weight: bold;
}
#fileElem {
display: none;
}
.center {
display: block;
margin-left: auto;
margin-right: auto;
width: 50%;
}
</style>
</head>
<body>
<div id="drop-area">
<form method='post' action='' enctype='multipart/form-data'>
<img src="Capture.png" alt="Upload" width="460" height="345" class="center">
<p>Edit your image here!</p>
<input type='file' name='files[]' multiple style="margin-left:39%"/>
<p><p><p>
<input type='submit' value='Submit' name='submit' class="button-1"/>
</form>
</div>
</body>
</html>