-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewlog.php
93 lines (65 loc) · 1.88 KB
/
viewlog.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
<?php
//$dir = '/tmp/logs1/';
//$files1 = scandir($dir);
function Sort_Directory_Files_By_Last_Modified($dir, $sort_type = 'descending', $date_format = "F d Y H:i:s.")
{
$files = scandir($dir);
$array = array();
foreach($files as $file)
{
if($file != '.' && $file != '..')
{
$now = time();
$last_modified = filemtime($dir.$file);
$time_passed_array = array();
$diff = $now - $last_modified;
$days = floor($diff / (3600 * 24));
if($days)
{
$time_passed_array['days'] = $days;
}
$diff = $diff - ($days * 3600 * 24);
$hours = floor($diff / 3600);
if($hours)
{
$time_passed_array['hours'] = $hours;
}
$diff = $diff - (3600 * $hours);
$minutes = floor($diff / 60);
if($minutes)
{
$time_passed_array['minutes'] = $minutes;
}
$seconds = $diff - ($minutes * 60);
$time_passed_array['seconds'] = $seconds;
$array[] = array('file' => $file,
'timestamp' => $last_modified,
'date' => date ($date_format, $last_modified),
'time_passed' => $time_passed_array);
}
}
usort($array, create_function('$a, $b', 'return strcmp($a["timestamp"], $b["timestamp"]);'));
if($sort_type == 'descending')
{
krsort($array);
}
return array($array, $sort_type);
}
$dir = '/tmp/logs1/';
$array = Sort_Directory_Files_By_Last_Modified($dir);
// Info Array
$files1 = $array[0];
// Sort Type
$sort_type = $array[1];
echo "<table border='1'><tr><td>SeqNo</td><td>FileName</td></tr>";
$count = 0;
foreach($files1 as $key=>$file)
{
if (!in_array($file,array(".","..")))
{
$count++;
echo "<tr><td>$count</td><td><a href='dispfile.php?filename=".$file['file']."'>".$file['file']."</a></td></tr>";
}
}
echo "</table>";
?>