-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.php
46 lines (43 loc) · 1.15 KB
/
image.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
<?php
function str_to_microtime($str) {
$l = explode('.', basename($str));
$tm = floatval(substr($l[0], 0, strlen($l[0]) - 1) . '.' . $l[1]);
return $tm;
}
function get_latest(&$num) {
$n = glob('uploads/*');
sort($n);
$time = 1200;
$tmp = array();
while (count($tmp) < 30 && count($tmp) < count($n)) {
$tmp = array_filter($n, function($e) use ($time) {
$current = microtime(TRUE);
$old = str_to_microtime($e);
$lapsed = ($current - $old);
return $lapsed < $time;
});
$time += 600;
}
$num = count($tmp);
return array_values($tmp);
}
if (isset($_GET["last"])) {
$last_path = $_GET["last"];
$cnt = 0;
$images = get_latest($cnt);
if ($last_path == $images[count($images) - 1]) {
echo $images[0];
} else {
for($i = 0; $i < count($images) - 1; ++$i) {
if ($last_path == $images[$i]) {
echo $images[$i + 1];
exit();
}
}
echo end($images);
}
} else if (isset($_GET["list"])) {
$imgs = glob('uploads/*');
sort($imgs);
echo json_encode($imgs);
}