-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·27 lines (24 loc) · 889 Bytes
/
index.php
File metadata and controls
executable file
·27 lines (24 loc) · 889 Bytes
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
<?php
require("config.inc.php");
function randomSelectIndex() {
$imgs = glob(IMG_DIR . IMG_EXTENSIONS, GLOB_BRACE);
$selectedIndex = array_rand($imgs);
setcookie("currentIndex", $selectedIndex);
return $selectedIndex;
}
function getImgFromIndex($index) {
$imgs = glob(IMG_DIR . IMG_EXTENSIONS, GLOB_BRACE);
if(IMG_NO_REPEAT_CURRENT && isset($_COOKIE['currentIndex'])):
while ($index == $_COOKIE['currentIndex']):
$index = randomSelectIndex();
endwhile;
endif;
$randomImage = $imgs[$index];
return $randomImage;
}
$currentSelectedIndex = randomSelectIndex();
$randomImage = getImgFromIndex($currentSelectedIndex);
header('Content-Type:image/jpeg');
header('Content-Length: ' . filesize($randomImage));
readfile($randomImage);
?>