-
Notifications
You must be signed in to change notification settings - Fork 0
/
welcome.php
173 lines (144 loc) · 5.09 KB
/
welcome.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
session_start();
// error_reporting(0);
require __DIR__."/lib/Library.php";
require "helper.php";
$app = new Library();
if (!(isset($_SESSION['id']))) {
header('Location:index.php?error=nologin');
}
//to file delete
// if(isset($_GET['id'])){
// $id = $_GET['id'];
// $query = "DELETE FROM upload WHERE id = $id";
// $result = $app->connection->query($query);
// $msg = 'File successfully deleted';
// }
$user = "SELECT * FROM users WHERE id='$_SESSION[id]'";
$user = $app->connection->query($user);
$user = $user->fetch(1);
?>
<!DOCTYPE html>
<html>
<head>
<title>File Management System</title>
<link type="text/css" rel="stylesheet" href="bootstrap/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="bootstrap/font-awesome/css/font-awesome.css">
<link type="text/css" rel="stylesheet" href="bootstrap/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="bootstrap/popper.min.js"></script>
<script type="text/javascript" src="bootstrap/jquery.min.js"></script>
<script type="text/javascript" src="bootstrap/bootstrap.min.js"></script>
</head>
<body>
<?php
if (!empty($_POST['upload']) && !empty($_FILES['file'])) {
$file = $_FILES['file'];
$name = input($_POST['name']);
$access = $_POST['access'];
if (empty($name)) {
aredirect("File name is empty...", "welcome.php");
}
if (empty($access)) {
aredirect("Please select an access type...", "welcome.php");
}
if (!($file['error']) && !empty($name) && !empty($access)) {
$fileName = $file['name'];
$fileExt = explode('.',$fileName)[1];
$fileSize = $file['size'];
$fileTmp = $file['tmp_name'];
$fileNewName = uniqid().'.'.$fileExt;
if($fileSize > 500000) {
aredirect("File too large", "welcome.php");
exit();
}
$statement = "INSERT INTO uploads (userid,name, file, access_level) VALUES('$_SESSION[id]', '$name', '$fileNewName', $access)";
try {
$app->connection->exec($statement);
move_uploaded_file($fileTmp, "uploads/".$fileName);
alert("File upload successful");
} catch (\PDOException $e) {
exit($e->getMessage());
}
}
}
?>
<div class="container-fluid">
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
<a href="#"><h5><span class="hd">AIMTOGET</span></h5></a>
<div class="header mr-auto">
<ul class="navbar-nav">
<li class="nav-item"><a class="nav-link" href="<?php $_SERVER['PHP_SELF']; ?>"><i style="color: white;" class="fa fa-user"></i></a></li>
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
</ul>
</div>
</nav>
<div class="container">
<div class="fm row">
<div class="col-8">
<table class="table table-striped">
<thead>
<tr>
<th>S/N</th>
<th>File Name</th>
<th>Access</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$statement = "SELECT * FROM uploads WHERE userid='$_SESSION[id]' ORDER BY id ASC";
$statement = $app->connection->query($statement);
foreach ($rows = $statement->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$name = $row['name'];
$id = $row['id'];
$filename = $row['file'];
$access = $row['access_level'];
if($access == '2') {
$access = 'Private';
}else {
$access = 'Public';
}
echo"<tr>
<td>$row[id]</td>
<td>$row[name]</td>
<td>$access</td>
<td><a href='#' data-toggle='modal' data-target='#confirm-delete$row[id]'>Delete</a></td>
<tr>
<div class='modal fade' id='confirm-delete$row[id]' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
<div class='modal-dialog'>
<div class='modal-content'>
<div class='modal-header'>
</div>
<div class='modal-body'>
Are you sure you want to delete this file
</div>
<div class='modal-footer'>
<button type='button' class='btn btn-default' data-dismiss='modal'>Cancel</button>
<a href='welcome.php?id=".$id."' class='btn btn-danger btn-ok'>Delete</a>
</div>
</div>
</div>
</div>";
}
?>
</tbody>
</table>
</div>
<div class="fm col-4">
<h2>Welcome <?php echo $user['username']; ?></h2>
<p>you can now upload your file</p>
</div>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="file" id="file">
<input type="text" name="name" id="name" placeholder="File Name" required>
<select name="access" id="access">
<option value="" disabled selected>Access Type</option>
<option value="1">Public</option>
<option value="2">Private</option>
</select>
<input type="submit" name="upload" value="upload file">
</form>
</div>
</body>
</html>