Image rotation on refresh.
Posted: Wed Jun 29, 2005 10:34 pm
Are there any PHP scripts that will change an image when the page is refreshed (or the page is loaded again)? Nothing fancy, I just need a simple PHP code. Thanks for your help.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$dir_of_images = '/path/to/directory/'; //Keep trailing slash
$handle = opendir($dir_of_images);
$images = array();
while ($file = readdir($handle)) { //Loop over the files
$ext = substr($file, -3);
if ($ext == 'jpg' || $ext = 'gif') { //Add any other 3 letter extensions here
$images[] = $file; //Store image in array
}
}
shuffle($images); //Shake them all up
echo '<img src="'.$dir_of_images.$images[0].'" alt="" />'; //Output the imageThanks, but even though I specified the directory of the images, they don't show up at all. Also, I need the images to be clickable.d11wtq wrote:Something like: