This repository was archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.php
More file actions
113 lines (92 loc) · 4.13 KB
/
index.php
File metadata and controls
113 lines (92 loc) · 4.13 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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/main.css">
<title>File Explorer</title>
</head>
<body>
<!--
TODO:
deletion-confirm menu
rename function
to do my own sort-files mechanic
to do white effect on the background of list
redesign header
redesign 'Back' button
-->
<?php
if (isset($_GET["dir"]) !== true) {
header("Location: ?dir=");
}
$dir = getcwd() . "/" . $_GET["dir"];
$files = array_diff(scandir($dir), array(".", ".."));
echo "<div id='container'>";
echo "<h4 id='current_directory'>/" . $_GET["dir"] . "</h4>";
echo "<button id='back_button' type='button' onclick='history.go(-1)'>Back</button>";
foreach ($files as $file) {
echo "<div class='box'>";
if (is_dir($file)) {
echo "<img class='folder_icon' src='http://localhost/file_explorer/img/rsz_folder.png'>";
echo "<a class='folder_link' href='?dir=" . $file . "'>" . $file . "</a>";
} else {
echo "<img class='file_icon' src='http://localhost/file_explorer/img/rsz_file.png'>";
if (empty($_GET["dir"])) {
echo "<a class='file_link' href=" . $file . ">" . $file . "</a>";
} else {
echo "<a class='file_link' href=" . $_GET["dir"] . "/" . $file . ">" . $file . "</a>";
}
echo "<p class='file_size'>" . size_units(filesize($dir . "/" . $file)) . "</p>";
}
$file_func = "'" . $file . "'";
$file_func = htmlspecialchars($file_func);
echo "<button onclick='open_dropdown($file_func)' class='file_manage_button' type='button'>";
echo "<img src=img/rsz_more.png>";
echo "</button>";
echo "<div onclick='file_delete($file_func)' data-type='delete_" . $file . "' id='dropdown_links'>";
echo "<img src=img/rsz_bin.png>";
echo "</div>";
echo "</div>";
}
echo "</div>";
?>
<script>
function open_dropdown(file) {
var file_name = "delete_" + file
var specific_file = document.querySelector("[data-type='" + file_name + "']");
// if (specific_file.style.display === "none") { // buggy, works only on second click
if (window.getComputedStyle(specific_file, null).getPropertyValue("display") === 'none') {
specific_file.style.display = "flex";
} else {
specific_file.style.display = "none";
}
}
function file_delete(file) {
let xhr = new XMLHttpRequest();
xhr.open("POST", "file_delete.php");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("file=" + encodeURIComponent(file));
location.reload()
}
</script>
<?php
function size_units($bytes) {
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . " GB";
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . " MB";
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . " KB";
} elseif ($bytes > 1) {
$bytes = $bytes . " bytes";
} elseif ($bytes == 1) {
$bytes = $bytes . " byte";
} else {
$bytes = "0 bytes";
}
return $bytes;
}
?>
</body>
</html>