Here is one of PHP, which depends only on the time of the last modification of the set of images in this directory:
<?php
function cmp($a, $b){
$atime = filemtime($a);
$btime = filemtime($b);
return $atime == $btime ? 0 : ($atime < $btime ? -1 : 1);
}
$paths = array();
if ($dh = opendir('images')){
while (($path = readdir($dh)) !== false){
if (substr($path, -4) == '.jpg'){
array_push($paths, "images/$path");
}
}
}
$count = count($paths);
$offset = time() % $count;
usort($paths, 'cmp');
for ($i = 0; $i < $offset; $i++){
$path = array_shift($paths);
array_push($paths, $path);
}
?>
Then, where you need it on your page:
<?php foreach ($paths as $path): ?>
<img src="<?php echo $path; ?>" ... />
<?php endforeach; ?>
source
share