Im trying to create a way for a way of several banners saved in a folder and a script to randomly select one of those images each time a page refreshes.
<img src="$banner_random">
And the $banner_random variable pulls from a folder called "banners" so say I had several banners in there labeled "banner1.gif banner2.gif banner3.gif" etc
OK.whats the question??
So... pick a random number from 1 to 3:
$filenum = rand(1,3);
Then, append the number to the file name:
$filename = "banner" . $filenum . ".gif";
Now, just use $filename to grab the file.
<?php $dir_file = array(); $i=0; if ($handle = opendir('./images')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $dir_file[$i++] = trim($file); } } closedir($handle); } echo '<img src="images/'.$dir_file[rand()%count($dir_file)].'" />'; ?>