-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
56 lines (45 loc) · 1.37 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
<?php
// Directory container
$directories = [];
// Get all files
$filesAndDirectories = scandir(".");
// Remove . and .. from array (=first two results)
$filesAndDirectories = array_slice( $filesAndDirectories, 3 );
// Loop over array containing paths
foreach ( $filesAndDirectories as $pathName)
{
// Check if the pathName is a directory
$isDir = is_dir( $pathName );
// and if it does not match a folder that needs to be ignored (ie. .git)
$shouldBeIgnored = ( preg_match( '/\.git/', $pathName ) === 1) ? true : false ;
// Check both conditions
if( $isDir && !$shouldBeIgnored ){
// Get modification timestamp of directory
$modifiedOnTimestamp = filemtime($pathName);
// Add path to directories array using timestamp_pathname as key and pathname as value;
$directories[ $modifiedOnTimestamp . '_' . $pathName ] = $pathName;
}
}
// Reverse sort array based on keys (prefixed with timestamp) -> highest timestamp first
krsort( $directories );
?>
<!DOCTYPE html>
<html lang="nl">
<head>
<meta charset="UTF-8">
<title>Web-backend</title>
<link rel="stylesheet" href="style_index.css" type="text/css">
</head>
<body>
<h1>Web-backend</h1>
<br>
<h3>Overzicht</h3>
<main>
<ul>
<?php foreach($directories as $key => $val):?>
<li><a href="<?= $directories[$key]?>/"><?= $directories[$key]?></a></li>
<?php endforeach;?>
</ul>
</main>
</body>
</html>