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
|
<?php
session_start();
function listdir_by_date($path){ $dir = opendir($path); $list = array(); while($file = readdir($dir)){ if ($file != '.' and $file != '..') { $ctime = filectime($path . "/". $file) . ',' . $file; $list[$ctime] = $file; } } closedir($dir); krsort($list); return $list; }
$files = listdir_by_date('./uploads'); $files = array_values($files);
$index = 0; $prevTotal = 0;
if(isset($_SESSION['currentIndex'])) { $index = $_SESSION['currentIndex']; } if(isset($_SESSION['prevTotal'])) { $prevTotal = $_SESSION['prevTotal']; }
$index++;
if($index >= $prevTotal) { $index = 0; }
$_SESSION['currentIndex'] = $index;
if(count($files) == 0) { $files[] = "3gc_logo.png"; }
$_SESSION['prevTotal'] = count($files); print_r('{"url":"' . "uploads/". $files[$index] . '"}');
?>
|