I have a folder that contains some various images in jpg, gif, etc format. I want to load the file names into an array so that I can then use them in a random generator to change images when the page refreshes.
How would I get the filenames into an array?
I have used a script to generate the images randomly as follows:
<?php
$picturesArray = array("trip_1.jpg", "trip_2.jpg",
"trip_5.jpg", "trip_6.jpg",
"trip_8.jpg", "trip_9.jpg",
"trip_12.jpg","trip_13.jpg",
"trip_14.jpg","trip_15.jpg");
srand((float) microtime() * 10000000);
shuffle($picturesArray);
echo "<img src=\"../../assets/images/Deschutes/$picturesArray[0]\"";
echo " alt=\"Deschutes River, Oregon\" >";
?>
But with this I have to save all the files as trip_1.jpg, trip_2.jpg, etc.
I would like to modify this so I could create the $picturesArray based on the filenames in the directory I want to access, then do the shuffle to mix them up, then echo out the one to show.
Any thoughts?