snorky Posted September 28, 2009 Share Posted September 28, 2009 How do I rotate images (or banners...) every n seconds? I use the following code to rotate the images every time the page is loaded. However, I want to rotate the images every n seconds while the page is displayed. <?php /* --------------------------------------------------------------------------------- find all files (in this case images) in a folder and rotate randomly when page is loaded or refreshed note: as written here, all files must be valid images and there can be no sub-folders --------------------------------------------------------------------------------- */ $filenum=0; // initialize counter $pix=array(); // create array $usedir="../images/const/"; // show location of images to rotate if ($handle = opendir($usedir)) // open folder for reading { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $file=$file++; // increment the counter $pix[]=$file; // select the next element from the array } } closedir($handle); } shuffle($pix); // shuffle the elements of the array $displ1=$pix[1]; // create var to id image to display $displ2=$pix[2]; // damphyno why I did this print // display the randomly-selected image "<img src='" . $usedir.$displ1 . "'><br />\n"; ?> To see the code in action: [*]http://www.maryellenoconnor.com/docs/silks.php [*]Refresh the page, then repeat, repeat .... Link to comment https://forums.phpfreaks.com/topic/175814-rotate-images-at-timed-intervals/ Share on other sites More sharing options...
smerny Posted September 28, 2009 Share Posted September 28, 2009 php doesn't do anything after the page is loaded... you'd have to use javascript or flash Link to comment https://forums.phpfreaks.com/topic/175814-rotate-images-at-timed-intervals/#findComment-926428 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.