-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-test.php
190 lines (163 loc) · 5.11 KB
/
index-test.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<html>
<head>
<title>7Learn File Manager</title>
<style type="text/css">
body, table {
font-family: tahoma;
font-size: 14px;
}
a, a:visited {
color: #1887e5;
text-decoration: none;
}
a:hover {
color: #555;
}
.back a {
color: brown !important;
}
ul {
list-style: none;
line-height: 22px;
}
li {
margin: 3px 0 0 0;
}
li:hover {
background-color: #f7f7f7 !important;
}
li.file, li.folder, li.png, li.gif, li.jpg, li.back {
padding-left: 24px;
color: #e6981c;
}
li.file {
background: transparent url("image/file.png") no-repeat left 3px;
}
li.folder {
color: #e6981c !important;
background: transparent url("image/folder.png") no-repeat left 3px;
}
li.back {
background: transparent url("image/back.png") no-repeat left 3px;
}
span.filename, .actions {
min-width: 300px;
display: inline-block;
}
.png, .jpg, .gif {
background: transparent url("image/img.png") no-repeat left 3px !important;
}
.htm,.html {
background: transparent url("image/html.png") no-repeat left 3px !important;
}
div.msg {
background-color: #ffd179;
padding: 7px;
margin: 10px;
}
</style>
</head>
<body>
<?php
/*
* @param string $file Filepath
* @param int $digits Digits to display
* @return string|bool Size (KB, MB, GB, TB) or boolean
*/
function getNiceFileSize($file, $digits = 2)
{
if (is_file($file)) {
$filePath = $file;
if (!realpath($filePath)) {
$filePath = $_SERVER["DOCUMENT_ROOT"] . $filePath;
}
$fileSize = filesize($filePath);
$sizes = array("TB", "GB", "MB", "KB", "B");
$total = count($sizes);
while ($total-- && $fileSize > 1024) {
$fileSize /= 1024;
}
return round($fileSize, $digits) . " " . $sizes[$total];
}
return false;
}
function rmDirectory($dir) {
foreach(glob($dir . '/*') as $file) {
if(is_dir($file)) rrmdir($file); else unlink($file);
} rmdir($dir);
}
if (isset($_GET['rm'])) {
$file2Remove = $_GET['rm'];
if(is_dir($file2Remove)){
rmDirectory($file2Remove);
echo "<div class='msg'>Directory $file2Remove and its content successfully deleted ...</div>";
}else{
@unlink($file2Remove);
echo "<div class='msg'>File $file2Remove successfully deleted ...</div>";
}
}
if(isset($_POST['filepath'],$_POST['filecontent'])){
file_put_contents($_POST['filepath'],$_POST['filecontent']);
echo "<div class='msg'>File {$_POST['filepath']} successfully saved ...</div>";
}
if (isset($_GET['edit'])) {
$file2edit = $_GET['edit'];
if (!file_exists($file2edit)) {
echo "<div class='msg'><b>Error :</b> File $file2edit not exists !</div>";
} else {
echo "Editing file $file2edit : <br>";
?>
<form action="" method="post">
<textarea name="filecontent" cols="100" rows="10"><?php echo file_get_contents($file2edit); ?></textarea><br>
<input name="filepath" type="hidden" value="<?php echo $file2edit; ?>"/>
<input type="submit" name="" value=" Save ">
</form>
<?php
}
}
if (isset($_GET['dir'])) {
$currDir = $_GET['dir'];
} else {
$currDir = 'files';
}
if (substr($currDir, strlen($currDir) - 1) != "/") {
$currDir .= '/';
}
echo '<h3>List of files in folder : <span style="color:brown">' . $currDir . '</span></h3>';
echo '<ul>';
echo '<li class="folder back">';
$parentDir = dirname($currDir);
echo '<span class="filename"><a href="?dir=' . $parentDir . '"> Go Back to ' . str_replace($currDir, '', $parentDir) . "</a></span>";
echo '</li>';
foreach (glob($currDir . '*') as $filename) {
$fileFormat = '';
if (is_dir($filename)) {
$type = 'folder';
} else {
$type = 'file';
$dotPosition = strrpos($filename, ".");
if ($dotPosition !== false) {
$fileFormat = substr($filename, $dotPosition + 1);
}
}
echo '<li class="' . $type . " $fileFormat " . '">';
if (is_dir($filename)) {
echo '<span class="filename"><a href="?dir=' . $filename . '">' . str_replace($currDir, '', $filename) . "</a></span>";
} else {
echo '<span class="filename">' . str_replace($currDir, '', $filename) . "</span>";
}
echo '<span class="actions">';
echo "<a href='?dir={$currDir}&rm={$filename}' " . ' onclick="return confirm(\'Are you sure to remove ' . $filename . ' \')" ' . "> delete </a>";
if (in_array($fileFormat, array('txt', 'php', 'html', 'htm'))) {
echo "<a href='?dir={$currDir}&edit={$filename}' > edit </a>";
}
echo '</span>';
echo '<span class="infos">';
echo getNiceFileSize($filename);
echo '</span>';
echo '</li>';
}
echo '</ul>';
?>
</body>
</html>