-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.php
95 lines (83 loc) · 2.65 KB
/
files.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>File Server</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div id="main"><div class="container"><div class="center">
<?php
//ensures that a username is provided as a session variable
session_start();
if (!isset($_SESSION["user"])) {
header("Location:login.html");
}
//determines path to the user's files
$user = $_SESSION["user"];
$dir = "/srv/uploads/users/{$user}";
//ensures that directory is valid
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
//doesn't create table if there are no files present
$isEmpty = true;
while (($file = readdir($dh)) !== false) {
if ("." === $file) continue;
if(".." === $file) continue;
$isEmpty = false;
break;
}
//creates table header
if (!$isEmpty) {
echo "
<table>
<thead>
<tr>
<th>Filename</th>
<th>Download</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
";
closedir($dh);
$dh = opendir($dir);
//creates rows of tables, each of which features the file name, a download button, and a delete button
while (($file = readdir($dh)) !== false) {
if ("." === $file) continue;
if(".." === $file) continue;
echo "<tr>";
echo "<td>$file</td>";
echo "<td><a href=\"download.php?file=$file\" class =\"button button2\">Download</a></td>";
echo "<td><a href=\"delete.php?file=$file\" class=\"button button1\">Delete</a></td>";
echo "</tr>";
}
closedir($dh);
echo "</tbody></table>";
//prints error message
} else {
echo "<p> Your directory is empty. Try uploading some files ;) </p>";
}
}
}
?>
<br>
<!-- form to upload new files -->
<form action="upload.php" method="POST" enctype="multipart/form-data">
Select a file to upload (max = 100 MB):
<input type="file" name="fileToUpload">
<input type="submit" value="Upload" name="submit">
</form>
<!-- logout form -->
<br>
<p>
<?php
echo "You are now logged in as user \"{$user}\".";
?>
Click "Logout" to return to the login page. </p>
<a href="abort.php" class="button button3">Logout</a>
</div></div></div>
</body>
</html>