I've decided to move the logic to PHP. So, I open the directory and stick all the file names in an array, randomize a number from zero to the total count of array indices and use that to display the image.
At first, this worked great - but I started noticing that images would randomly not be displayed. So I started keeping track of the index used - and it was consistently several of the indices - 3, 11, etc. Of course, I checked the files and none of them are corrupt.
This is a very weird problem. Anyone have any ideas?
<?php
// look at the directory - count the number of images and stick them into an array:
$myDirectory = opendir("./images") ;
// Get each file:
while($file = readdir($myDirectory))
{
$dirArray1[] = $file ;
}
closedir($myDirectory) ;
// Generate a random number:
$fileIndex1 = rand(0,(count($dirArray1))) ;
echo "
<div><img src=\"./images/$dirArray1[$fileIndex1]\" alt=\"\" /></div>
" ;
?>
This post has been edited by Galaxy_Stranger: 07 December 2010 - 10:17 PM

New Topic/Question
Reply




MultiQuote




|