-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathfile-list.php
65 lines (54 loc) · 1.44 KB
/
file-list.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
<?php
function listFiles($prefix) {
echo '<table class="table table-striped table-hover">';
echo "<thead>";
echo "<tr>";
echo '<th class="text-center col-md-2">Date</th>';
echo "<th>Filename</th>";
echo '<th class="text-right col-md-4">Size</th>';
echo "</tr>";
echo "</thead>";
echo "<tbody>";
include "files.php";
date_default_timezone_set ( 'UTC' );
rsort ( $files );
$count = 0;
foreach ( $files as $file ) {
if ($count < 5) {
$refname = basename ( $file );
if (substr ( $refname, 0, strlen ( $prefix ) ) == $prefix) {
$count = $count + 1;
$stat = stat ( $file );
$date = date ( 'Y-m-d', $stat ['mtime'] );
$size = formatBytes ( $stat ['size'] );
$date = "unknown";
$size = "unknown";
echo "<tr class='clickable'>";
echo "<td class='text-center'>$date</td>";
echo "<td><a href='$file' target='_blank'><i class='glyphicon glyphicon-cloud-download'></i> $refname</a></td>";
echo "<td class='text-right'>$size</td>";
echo "</tr>";
}
}
}
echo "</tbody>";
echo "</table>";
if($count==0){
echo "No files found with prefix ".$prefix;
}
}
function formatBytes($bytes, $precision = 2) {
$units = array (
'B',
'KB',
'MB',
'GB',
'TB'
);
$bytes = max ( $bytes, 0 );
$pow = floor ( ($bytes ? log ( $bytes ) : 0) / log ( 1024 ) );
$pow = min ( $pow, count ( $units ) - 1 );
$bytes /= pow ( 1024, $pow );
return round ( $bytes, $precision ) . ' ' . $units [$pow];
}
?>