Laatst gewijzigde bestanden ook in submappen tonen
Vooreerst wil ik zeggen dat ik nieuw ben (lees beginner) in PHP en daardoor nog heel veel moet bijleren.
Ik heb bezig met een script dat de laatst gewijzigde bestanden toont (nieuwste bovenaan, oudste onderaan).
zie Voorbeeld:
Leden - page02.php
Laatst Gewijzigd op maandag 04 april 2011 - 16:02:05
6 minuten, 45 seconden geleden
Home - page01.php
Laatst Gewijzigd op zondag 03 april 2011 - 15:31:01
1 dag, 37 minuten, 49 seconden geleden
etc...
Nu dit script leest alleen de php en html bestanden uit de "root"map maar ik zou graag hebben dat dit ook bestanden uit sommige submappen leest. Ik heb reeds op het internet gezocht maar ik raak er niet uit. Wie kan mij helpen zodat onderstaande code ook php en html bestanden uit sommige subdirectories toont.
Wie kan mij helpen en de code aanvullen ?
Alvast bedankt voor jullie inzet.
Vriendelijke groeten
Coderunner
Code (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
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
<html>
<head>
<title>Laatst gewijzigde bestanden</title>
</head>
<body>
<?php
setlocale(LC_ALL, 'nld_nld');
/* Output: vrijdag 22 december 1978 */
//echo strftime("%A %d %B %Y");
date_default_timezone_set('Europe/Brussels');
function Sort_Directory_Files_By_Last_Modified($dir, $sort_type = 'descending', $date_format = "%A %d %B %Y - %X")
{
$files = scandir($dir);
$array = array();
foreach($files as $file)
{
if($file != '.' && $file != '..' && (preg_match("/\\.php$/", $file) || preg_match("/\\.html$/", $file) || preg_match("/\\.htm$/", $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['uren'] = $hours;
}
$diff = $diff - (3600 * $hours);
$minutes = floor($diff / 60);
if($minutes)
{
$time_passed_array['minuten'] = $minutes;
}
$seconds = $diff - ($minutes * 60);
$time_passed_array['seconden'] = $seconds;
$text = file_get_contents($file);
if(preg_match('#<title>([\w\s]*)</title>#is', $text, $matches))
{
$array[] = array('file' => $file,
'timestamp' => $last_modified,
'date' => strftime ($date_format, $last_modified),
'title' => $matches[1],
'time_passed' => $time_passed_array);
} else {
$array[] = array('file' => $file,
'timestamp' => $last_modified,
'date' => strftime ($date_format, $last_modified),
'title' => ("Geen Titel"),
'time_passed' => $time_passed_array);
}
}
}
usort($array, create_function('$a, $b', 'return strcmp($a["timestamp"], $b["timestamp"]);'));
if($sort_type == 'descending')
{
krsort($array);
}
$array = array_slice($array, 0, 5);
return array($array, $sort_type);
}
//Example of usage:
// $dir = '/home/public_html/my_directory/';
$dir = './';
$array = Sort_Directory_Files_By_Last_Modified($dir);
// Info Array
$info = $array[0];
// Sort Type
$sort_type = $array[1];
// echo '<h3>'.$dir.'</h3>';
// echo 'Order by: Last Modified ('.$sort_type.')<br>';
foreach($info as $key => $detail)
{
echo '<b>'.$detail['file'].'</b> - '.$detail['title'].'<br />';
echo 'Laatst Gewijzigd op '.$detail['date'].'<br>';
$time_passed = '';
foreach($detail['time_passed'] as $type => $value)
{
$time_passed .= $value." ".$type.", ";
}
$time_passed = "<span>".rtrim($time_passed, ", ")."</span> geleden<br /><br />";
echo $time_passed."";
}
?>
</body>
</html>
<head>
<title>Laatst gewijzigde bestanden</title>
</head>
<body>
<?php
setlocale(LC_ALL, 'nld_nld');
/* Output: vrijdag 22 december 1978 */
//echo strftime("%A %d %B %Y");
date_default_timezone_set('Europe/Brussels');
function Sort_Directory_Files_By_Last_Modified($dir, $sort_type = 'descending', $date_format = "%A %d %B %Y - %X")
{
$files = scandir($dir);
$array = array();
foreach($files as $file)
{
if($file != '.' && $file != '..' && (preg_match("/\\.php$/", $file) || preg_match("/\\.html$/", $file) || preg_match("/\\.htm$/", $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['uren'] = $hours;
}
$diff = $diff - (3600 * $hours);
$minutes = floor($diff / 60);
if($minutes)
{
$time_passed_array['minuten'] = $minutes;
}
$seconds = $diff - ($minutes * 60);
$time_passed_array['seconden'] = $seconds;
$text = file_get_contents($file);
if(preg_match('#<title>([\w\s]*)</title>#is', $text, $matches))
{
$array[] = array('file' => $file,
'timestamp' => $last_modified,
'date' => strftime ($date_format, $last_modified),
'title' => $matches[1],
'time_passed' => $time_passed_array);
} else {
$array[] = array('file' => $file,
'timestamp' => $last_modified,
'date' => strftime ($date_format, $last_modified),
'title' => ("Geen Titel"),
'time_passed' => $time_passed_array);
}
}
}
usort($array, create_function('$a, $b', 'return strcmp($a["timestamp"], $b["timestamp"]);'));
if($sort_type == 'descending')
{
krsort($array);
}
$array = array_slice($array, 0, 5);
return array($array, $sort_type);
}
//Example of usage:
// $dir = '/home/public_html/my_directory/';
$dir = './';
$array = Sort_Directory_Files_By_Last_Modified($dir);
// Info Array
$info = $array[0];
// Sort Type
$sort_type = $array[1];
// echo '<h3>'.$dir.'</h3>';
// echo 'Order by: Last Modified ('.$sort_type.')<br>';
foreach($info as $key => $detail)
{
echo '<b>'.$detail['file'].'</b> - '.$detail['title'].'<br />';
echo 'Laatst Gewijzigd op '.$detail['date'].'<br>';
$time_passed = '';
foreach($detail['time_passed'] as $type => $value)
{
$time_passed .= $value." ".$type.", ";
}
$time_passed = "<span>".rtrim($time_passed, ", ")."</span> geleden<br /><br />";
echo $time_passed."";
}
?>
</body>
</html>
Ik heb het zelf reeds gevonden.