-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.php
55 lines (51 loc) · 1.65 KB
/
display.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
<?php
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
$limit=100;
function getImages($dir)
{
// array to hold return value
$retval = [];
// add trailing slash if missing
if(substr($dir, -1) != "/") {
$dir .= "/";
}
$filecount=0;
// full server path to directory
$fulldir = "{$_SERVER['DOCUMENT_ROOT']}/$dir";
$retval=glob($fulldir."*.jpg");
usort($retval, create_function('$a,$b', 'return filemtime($a)<filemtime($b);'));
return $retval;
}
$images = getImages("files");
$img_count=count($images);
$max_pages = ceil($img_count / $limit);
if(isset($_GET["page"])){
$show = array_slice($images, $limit * intval($_GET["page"]) - 1, $limit);
}
else{
$show=array_slice($images, 0, 100);
}
// display on page
echo" <meta http-equiv=\"refresh\" content=\"30\"/>";
echo "<h1 style='text-align:center' > There are {$img_count} images </h1>";
foreach($show as $img) {
$img_path="/files/".basename($img);
echo "<img class=\"photo\" src=\"{$img_path}\" alt=\"\" style=\"margin-left: 5%;\" >\n";
}
echo("<br><br><br>");
if(isset($_GET["page"])){
if($_GET['page'] > 1){
$prev_link = '<a href="?page='.($_GET['page']-1).'" > <p style="text-align:center"> previous </p> </a>';
echo($prev_link);
}
if($_GET['page'] < $max_pages){
$next_link = '<a href="?page='.($_GET['page']+1).'" > <p style="text-align:center"> next </p> </a>';
echo($next_link);
}
}
else{ //deal with the very first page
$next_link = '<a href="?page=2" > <p style="text-align:center"> next </p> </a>';
echo($next_link);
}
?>