Conjurer Posted February 5, 2007 Share Posted February 5, 2007 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 Code: <?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? Link to comment https://forums.phpfreaks.com/topic/37089-how-can-i-create-array-based-on-files-in-a-directory-folder/ Share on other sites More sharing options...
trq Posted February 5, 2007 Share Posted February 5, 2007 $picturesArray = scandir('pics/'); Link to comment https://forums.phpfreaks.com/topic/37089-how-can-i-create-array-based-on-files-in-a-directory-folder/#findComment-177137 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.