said by Gwellin:...although I would personally use PHP to do that.
Me too.
said by Mike D0:I'm not really looking for anyone to post code...
I just can't help myself. ;)
php code:
<?php
// CONFIGURATION SECTION
//
//
//Which types of files should we allow to be in the list from which we will randomly choose?
$extensionsToAllow = array(
'jpg',
'gif',
'png'
);
//Should the above file extensions be handled case sensitively?
$extensionsCaseSensitive = false;
//
//
// NO FURTHER CONFIGURATIONS - DO NOT EDIT BELOW THIS LINE
$cwd = dirname(realpath(__FILE__));
if(is_dir($cwd)){
$openedDir = @opendir($cwd);
if($openedDir !== false){
$URItoDir = 'http://'.$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'],'',$cwd).'/';
$fileList = array();
while(false !== ($file = readdir($openedDir))){
if($file!='.' && $file!='..' && $file!=basename(__FILE__)){
$extensionsCaseSensitive===false ? $filename = strtolower($file) : $filename = $file;
foreach($extensionsToAllow as $ext){
if($extensionsCaseSensitive===false){
$ext = strtolower($ext);
}
if(substr($filename,-(strlen($ext)))==$ext){
$fileList[] = $file;
break;
}
}
}
}
closedir($openedDir);
if(count($fileList)>0){
$fileURI = $URItoDir.$fileList[array_rand($fileList)];
echo "<img src=\"$fileURI\" alt=\"\" />";
}
}
}
?>
1) Create a directory on your server to hold the images which should be randomly selected.
2) Place a file with the above PHP code in that directory along with the images.
3) Adjust the configuration lines if necessary (I doubt it will be necessary...most of this is self configuring.)
4) From anywhere on your site, include() the code file from step 2 and one of your images should be randomly outputted.
Jim