Forum Moderators: open
It is easiest to place this in the same folder as the files you want to rotate randomly.
Call it as if it was an image. (here assume you name the php file rotate.php)
<img src="rotate/rotate.php">
<?php
$folder = "/full path here/";
$fileList = array();
$handle = opendir($folder);
while (false!== ($file = readdir($handle) ) ) {
if ( substr($file, -4) == ".gif" ¦¦ substr($file, -4) == ".jpg" ) {
$fileList[count($fileList)] = $file;
}
}
closedir($handle);
$randNum = rand( 0, (sizeOf($fileList) -1) );
if ( substr($fileList[$randNum], -4) == ".gif" ) {
header ("Content-type: image/gif");
} elseif ( substr($fileList[$randNum], -4) == ".jpg" ) {
header ("Content-type: image/jpeg");
}
readfile($fileList[$randNum]);
?>