11-06-2009, 05:55 AM
Credits and Source: http://www.dreamincode.net/
Name: Banner Rotation
Description: On Refresh of a page, this script selects a random banner from the /banners/ directory to show.
Snippet:
Instructions: just include the code the code in your script, and put all your banners into the /banners/ directory
Though this can be changed by editing the $directory variable at the start of the code.
Thankyou
Name: Banner Rotation
Description: On Refresh of a page, this script selects a random banner from the /banners/ directory to show.
Snippet:
PHP Code:
/**
* @author Furnfield
* @email furnfield@googlemail.com
* @copyright 2009
* @project RBanner
**/
$directory = './banners/'; //Directory where Banners are located with opening ./ and trailing .
$directory2 = 'banners/'; //Directory where Banners are located with trailing /
$i = '0'; // $i is a variable used in the naming of the array, so we set it to be 0 initally
$dir = opendir ($directory); //Open the directory
while (false !== ($file = readdir($dir)))
{
if($file != '.' && $file != '..' && exif_imagetype($directory.$file) != false)
{
$farray[$i] = $file; //Select the image files and put them into an array
$i++; // add 1 to $i
}
}
//Due to the final $i++;, $i is one value too large
$rand = rand(0, $i - 1); //Create a Random number 0 <= $rand <= $i-1
$rand_file = $farray[$rand]; //Select the file from the array with the value $rand
echo '<img src="'.$directory2.$rand_file.'">'; //output image file
Instructions: just include the code the code in your script, and put all your banners into the /banners/ directory
Though this can be changed by editing the $directory variable at the start of the code.
Thankyou