Hi. I’d like to receive an image from an array, sequentially, after I click a button.
So when I first click on a button an image (Axajafied) will appear on my page. When I hit the button again I’d like the next image in the array to appear, and so on. I have the javascript / Ajax part working correctly. However my PHP code (where the request is received) is where I need to implement this. Currently I have a technique where I shuffle the array and choose the last element of the array. See attached code.
Thanks
// MAKE AN ARRAY OF THE JPG IMAGE FILE NAMES
$b = array();
while (($filename = readdir($dh)) !== FALSE)
{
// CHOOSE ONLY JPG IMAGES
$file_ext = strtoupper(end(explode(‘.’, $filename)));
if ($file_ext != ‘JPG’) continue;
$b[] = $filename;
}
closedir($dh);
// MAKE AN ARRAY OF THE JPG IMAGE FILE NAMES
// WITH ALL FILE NAMES IN AN ARRAY, RANDOMIZE THE LIST AND CHOOSE ONE
shuffle($b);
$banner_name = array_pop($b);
$banner_url = $my_dir . $banner_name;
}