Sentinel47 0 Report post Posted October 8, 2018 Hi all, I'm trying to create a Carousel (with Bootstrap) that will obtain and display only the last 4 uploaded images from a specified directory (uploads/). I have a form on another page that allows user submission of an image, which then moves it to the uploads folder. From there, I'm not sure how to begin writing the code to obtain the last 4 images from the directory. Share this post Link to post Share on other sites
justsomeguy 1,093 Report post Posted October 8, 2018 You won't be able to do that with just Javascript, you'll need a server-side language to read the directory contents and print the filenames into an array that you can use. 1 Share this post Link to post Share on other sites
Sentinel47 0 Report post Posted October 9, 2018 Thanks for your reply, Sorry for the confusion, but yeah I'm intending to use PHP to achieve this. Share this post Link to post Share on other sites
iwato 16 Report post Posted October 9, 2018 (edited) Where and how have you stored the images? In a folder or in a data base? If in a folder does each image have a filename that reflects the order in which it was saved? If in a data base, are you using a time stamp with each entry? Roddy Edited October 9, 2018 by iwato Share this post Link to post Share on other sites
justsomeguy 1,093 Report post Posted October 9, 2018 You can use a DirectoryIterator to loop through the files in the directory and save the filename and last modified date of each file in an array, then use something like asort to sort the array by the timestamp. http://php.net/manual/en/directoryiterator.getmtime.php If you saved the array where the key is the filename, and the value is the timestamp, you can use asort to sort it in chronological order. http://php.net/manual/en/function.asort.php Share this post Link to post Share on other sites