-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorarea.php
More file actions
191 lines (144 loc) · 4.9 KB
/
tutorarea.php
File metadata and controls
191 lines (144 loc) · 4.9 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php include 'includes/head.php';
function prePad($level){
$ss = "";
for ($ii = 0; $ii < $level; $ii++)
{
$ss = $ss . "| ";
}
return $ss;
}
function myScanDir($dir, $level)
{
global $pathLen;
if ($handle = opendir($dir)) {
$allFiles = array();
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir('uploads'.$_GET['dir'] . $entry))
{
$allFiles[] = "D: " . $_GET['dir'] . $entry;
}
else
{
$allFiles[] = "F: " . $_GET['dir'] . $entry;
}
}
}
closedir($handle);
natsort($allFiles);
if ($_GET['dir'] !== "/"){
echo "<i class=\"fa fa-level-up\"></i> <a href=\"tutorarea.php?dir=".substr($_GET['dir'], 0, strrpos( substr($_GET['dir'],0,-1), '/'))."/\">Up a level</a><br>";
}
foreach($allFiles as $value)
{
$current = $_GET['dir'];
$displayName = substr($value, strlen($current) + 3);
$fileName = 'uploads'.substr($value, 3);
$linkName = str_replace(" ", "%20", substr($value, $pathLen + 3));
if (is_dir($fileName)) {
echo prePad($level) ."<i class=\"fa fa-folder\"></i> <a href=\"tutorarea.php?dir=".$linkName."/\">".$displayName."</a> <br>\n";
} else {
$file_parts = pathinfo($fileName);
switch($file_parts['extension']){
case "pdf":
echo '<i class="fa fa-file-pdf-o"></i>';
break;
case "jpg":
echo '<i class="fa fa-file-image-o"></i>';
break;
case "png":
echo '<i class="fa fa-file-image-o"></i>';
break;
case "gif":
echo '<i class="fa fa-file-image-o"></i>';
break;
case "svg":
echo '<i class="fa fa-file-image-o"></i>';
break;
case "doc":
echo '<i class="fa fa-file-word-o"></i>';
break;
case "docx":
echo '<i class="fa fa-file-word-o"></i>';
break;
case "xls":
echo '<i class="fa fa-file-excel-o"></i>';
break;
case "xlsx":
echo '<i class="fa fa-file-excel-o"></i>';
break;
case "ppt":
echo '<i class="fa fa-file-powerpoint-o"></i>';
break;
case "zip":
echo '<i class="fa fa-file-zip-o"></i>';
break;
}
echo prePad($level) . " <a href=\"download.php?filename=" . $linkName . "\" style=\"text-decoration:none;\">" . $displayName . "</a><br>\n";
}
}
}
}
echo '<div class="content" style="text-align: left">';
if (login_check($mysqli) !== false) {
echo '<p>Welcome '.htmlentities($_SESSION['username']).' ('. login_check($mysqli).')</p>';
$dir = "uploads".$_GET['dir'];
$dir = realpath($dir);
if (strpos($dir, "public_html\uploads") !== false || strpos($dir, "public_html/uploads") !== false ){
if (login_check($mysqli) == "admin") {
$dir2 = $_GET['dir'];
echo '<form action="upload.php?dir='.$_GET['dir'].'" method="post" enctype="multipart/form-data">';
echo ' upload a new file:';
echo ' <input type="file" name="fileToUpload" id="fileToUpload">';
echo ' <input type="submit" value="Upload File" name="submit">';
echo '</form>';
echo ' <br>';
echo ' <form action="delete.php?dir='.$_GET['dir'].'" method="post" enctype="multipart/form-data">';
echo ' Name of file/folder to delete:';
echo ' <select name="fileToDelete" id="fileToDelete">';
if ($handle = opendir($dir)){
$allFiles = array();
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir($dir . "/" . $entry))
{
$allFiles[] = "D: " . "/" . $entry;
}
else
{
$allFiles[] = "F: " . "/" . $entry;
}
}
}
closedir($handle);
natsort($allFiles);
foreach($allFiles as $value){
$fileName = substr($value, 3);
$linkName = str_replace(" ", "%20", $fileName);
$fileName = substr($fileName, 1);
$linkName = substr($linkName, 1);
echo '<option value="' . $fileName . '">' . $fileName . '</option>';
}
}
echo ' </select>';
echo ' <input type="submit" value="Delete (Permanent)" name="submit">';
echo ' Note folders can only be deleted if they are empty';
echo '</form>';
echo ' <form action="newfolder.php?dir='.$dir2.'" method="post" enctype="multipart/form-data">';
echo ' Name of folder';
echo ' <input type="text" id="foldername" name="foldername"/>';
echo ' <input type="submit" value="Create Folder" name="submit">';
echo '</form>';
}
myScanDir($dir, 0);
}else {
echo 'Error: File path not valid';
}
}else{
echo '<p>';
echo ' <span class="error">You are not authorised to access this page.</span> Please <a href="login.php">login</a>.';
echo '</p>';
}
echo '</div>';
include 'includes/footer.php';
?>