Load Random Images from Directory
Load Random Images from Directory I'd like to randomly load images from a directory and have a button somewhere that refreshes the entire page. Here's the current code I have now: <?php $a = array(); $dir = '../public/wp-content/uploads/2012/01'; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (preg_match("/.png$/", $file)) $a = $file; elseif (preg_match("/.jpg$/", $file)) $a = $file; elseif (preg_match("/.jpeg$/", $file)) $a = $file; } closedir($handle); } foreach ($a as $i) { echo "<img src='" . $dir . '/' . $i . "' />"; } ?> The problem is it loads all 400,000 images at once. I only want 30 to load. 30 random images from the directory. I tried looking up some code such as modifying the above to this: <?php $a = array(); $dir = '../public/wp-content/uploads/2012/01'; if ($handle = opendir($dir)) { while (false !== ($file = re...