forked from mul14/file-manager
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.php
161 lines (146 loc) · 4.67 KB
/
index.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
<?php
function timeAgo($tm,$rcs = 0) {
$cur_tm = time(); $dif = $cur_tm-$tm;
$pds = array('second','minute','hour','day','week','month','year','decade');
$lngh = array(1,60,3600,86400,604800,2630880,31570560,315705600);
for($v = sizeof($lngh)-1; ($v >= 0)&&(($no = $dif/$lngh[$v])<=1); $v--); if($v < 0) $v = 0; $_tm = $cur_tm-($dif%$lngh[$v]);
$no = floor($no); if($no <> 1) $pds[$v] .='s'; $x=sprintf("%d %s ",$no,$pds[$v]);
if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm);
return $x;
}
function formatSizeUnits($bytes) {
if ($bytes >= 1073741824) {
$bytes = number_format($bytes / 1073741824, 2) . ' GiB';
} elseif ($bytes >= 1048576) {
$bytes = number_format($bytes / 1048576, 2) . ' MiB';
} elseif ($bytes >= 1024) {
$bytes = number_format($bytes / 1024, 2) . ' KiB';
} elseif ($bytes > 1) {
$bytes = $bytes . ' bytes';
} elseif ($bytes == 1) {
$bytes = $bytes . ' byte';
} else {
$bytes = '0 bytes';
}
return $bytes;
}
function curPageURL() {
$pageURL = '?';
if (isset($_SERVER['HTTP_HOST'])) {
$pageURL = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https' : 'http';
$pageURL .= '://' . $_SERVER['HTTP_HOST'];
$pageURL .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
}
return $pageURL;
}
define('DS', DIRECTORY_SEPARATOR);
$url = curPageURL();
$path = realpath('');
setlocale(LC_ALL, 'IND');
$dateFormat = '%c';
$finfo = new finfo(FILEINFO_MIME_TYPE);
$hideThisFile = array(
'Thumbs.db', 'desktop.ini',
);
$hideThisPattern = array('/~$/', '/^\./');
$dirs = scandir($path);
$directories = $files = $items = array();
natcasesort($dirs);
$i = 0;
foreach ($dirs as $dir) {
if (!is_readable($path.DS.$dir)) continue;
if (in_array($dir, $hideThisFile)) continue;
$excludeThisFile = false;
foreach($hideThisPattern as $pattern) {
if (preg_match($pattern, $dir)) $excludeThisFile = true;
}
if ($excludeThisFile) continue;
$items[$i] = array(
'name' => $dir,
'ext' => pathinfo($dir, PATHINFO_EXTENSION),
'mime' => $finfo->file($path.DS.$dir),
'size' => formatSizeUnits(filesize($path.DS.$dir)),
'created' => strftime($dateFormat, filectime($path.DS.$dir)),
'created_ago' => timeAgo(filectime($path.DS.$dir)),
'modified' => strftime($dateFormat, filemtime($path.DS.$dir)),
'modified_ago' => timeAgo(filemtime($path.DS.$dir)),
'mime' => $finfo->file($path.DS.$dir),
);
if (is_dir($path.DS.$items[$i]['name'])) {
$items[$i]['name'] = $items[$i]['name'].'/';
$directories[] = $items[$i];
} else {
$files[] = $items[$i];
}
$i++;
}
$dirs = array_merge($directories, $files);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Landing Page</title>
<style>
* {
padding: 0; margin: 0;
}
html {
font-size: 62.5%;
}
body {
font-family: sans-serif;
font-size: 1.3rem;
}
table {
width: 100%;
border: 1px solid #cecece;
border-collapse: collapse;
}
thead tr {
background: #e1e1e1;
}
table th {
border: 1px solid #cecece;
padding: 4px 8px;
text-align: left;
}
table td {
border-bottom: 1px solid #cecece;
padding: 4px 8px;
}
.align-right {
text-align: right
}
</style>
</head>
<body>
<h1><?php echo $path ?></h1>
<table>
<thead id="thead">
<tr>
<th><a href="#">Name</a></th>
<th><a href="#">Extension</a></th>
<th><a href="#">Mime</a></th>
<th><a href="#">Size</a></th>
<th><a href="#">Modified</a></th>
<th><a href="#">Created</a></th>
</tr>
</thead>
<tbody>
<?php foreach ($dirs as $dir): ?>
<tr>
<td>
<a href="<?php echo $url.$dir['name'] ?>"><?php echo $dir['name'] ?></a>
</td>
<td><?php echo $dir['ext'] ?></td>
<td><?php echo $dir['mime'] ?></td>
<td class="align-right"><?php echo $dir['size'] ?></td>
<td><?php echo $dir['modified'] ?> / <?php echo $dir['modified_ago'] ?> ago</td>
<td><?php echo $dir['created'] ?> / <?php echo $dir['created_ago'] ?> ago</td>
</tr>
<?php endforeach ?>
</tbody>
<table>
</body>
</html>