Something rather annoying about this post being stretched out like this, but never mind lol
Ok I'm going to write a function below for you so you can select a random image from a random folder each time the function is called.
What I have done is basically taken the coding example from here (so the credit really goes to that person) and just added a bit of extra functionality
too incorporate multiple folders.function getRandomImage(){ // Change directories to your image directories, you can also add more if you wish eg. $randir[2] = 'images/randomdirectory3/'; just remember to add the trailing slash $randir[0] = 'images/randomdirectory1/'; $randir[1] = 'images/randomdirectory2/'; $getrandir = array_rand($randir, 1); $dir=opendir($randir[$getrandir[0]]); $i=0; while($imgfile = readdir($dir)){ if (($imgfile != ".") && ($imgfile != "..")){ $imgarray[$i] = $imgfile; $i++; } } closedir($dir); $rand=rand(0,count($imgarray)-1); if($rand >= 0){ return '<img src="'.$randir[$getrandir[0]].''.$imgarray[$rand].'" width="170" height="137">'; } }
So now all you have to do is change the following lines:
$randir[0] = 'images/randomdirectory1/';
$randir[1] = 'images/randomdirectory2/';
to the directorys you want to pull a random image from and like I stated in the comments, you can add more directories if you wish.
So now you have changed your directories all you need to do is echo the function and it will display your image.
echo getRandomImage();
I haven't tested the modified code but looking over it there shouldn't be a problem, let me know if it works.
I made a new topic since this really was getting annoying.
Here's the new topic.




