This is a function to randomly include text or an image from any specified directory. I got the idea and some of the code somewhere, but can't recall where. Think was from the examples on the PHP function page for srand.
To use: 1) copy the function and include in your php file, 2) call the randomizer(); function.
1. Copy this code
################################################################################
# Random img and text generator
################################################################################
// $type = img or text
// $server_dir is the unix directory where your files are
// $www_dir is the www directory where your files are. can be "" for text
function randomizer ($type,$server_dir,$www_dir){
$handle=opendir($server_dir);
$counter = 0;
//load array with file names
while ($file = readdir($handle)) {
if ($file != "." && $file != ".."){
$arr_Images[$counter] = $file;
$counter++;
}
}
closedir($handle);
srand((double)microtime()*1000000);
$randID = rand(0,$counter - 1);
if($type=="img"){
echo "<img src=\"$www_dir/$arr_Images[$randID]\" border=\"0\" />";
} elseif ($type=="text") {
include("$server_dir/$arr_Images[$randID]");
}
} # end function
2. Call the function
To call the function, insert this code somewhere on a php page,
randomizer('[type:img|text]','[server path to directory],'[http path to directory]');
for example, this is how I call the function to include a random image:
randomizer('img','/u4/angeles/public_html/studio/img/home_hilite','/img/home_hilite');