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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>/log/img</title>
<link href="../style.css" rel="stylesheet" type="text/css" media="all">
<?php include("../seasonal.php"); ?>
<style>
.dir {
padding: 1rem;
padding-top: 2rem;
}
article.imgs {
display: flex;
flex-wrap: wrap;
border-bottom: none;
}
a.img {
display: flex;
flex-direction: column;
}
a.img :is(img, span) {
margin: 1rem;
}
h2 {
margin: 1rem;
margin-bottom: 0;
}
</style>
</head>
<body>
<nav><a href="../"><<<</a></nav>
<p>$ pwd</p>
<h1 class="title">/log/img</h1>
<p>$ ls -t</p>
<section class="dir">
<?php
$imagetimes = Array();
function test_image($name) { // Returns true if a file is an image (png or gif), false otherwise
return (strpos($name, ".png") > 0 or strpos($name, ".gif") > 0 or strpos($name, ".jxl") > 0);
}
function imagetime($file) { // This needs to return a Unix timestamp.
global $imagetimes;
if(!$imagetimes[$file]) {
$imagetimes[$file] = filemtime($file);
}
return $imagetimes[$file];
}
$images = array_filter(scandir("."), "test_image"); // Generate array of every image in the directory by filename
usort($images, function($a, $b) { // Sort images by modification date of the files
return imagetime("$b") - imagetime("$a");
});
$pmt = "";
foreach($images as $im) { // Loops through each image and echoes it to the page
$no = substr($im, 0, strpos($im, ".")); // Filename with extension stripped
$mt = date("Y-m-d", imagetime("$im")); // File modification date in ISO format
$is = getimagesize("$im");
$ist = $is[0] . "×" . $is[1]; // Image size formatted as X×Ypx
if($pmt != $mt) {
if($pmt != "") {
echo "</article>";
}
$pmt = $mt;
echo "<h2>$mt</h2><article class='imgs'>";
}
echo("<a class='img' href='/img/$im'><img src='/img/thumbs/$no.jpg'><span>$im >> $ist</span></a>");
}
?>
</section>
<p>$</p>
</body>
</html>
|