This tutorial teaches you how to build a system that uses an array to display all the images in a specified directory on your server in a randomized format using PHP.
The script is easy to understand as it uses just two functions whicg are as follows:
(1) vpb_getImagesFromFolder: This function contains three fields which are (1) The directory where your images are located on your server, (2) Your desired width for your images and (3) Your desired height for your images.
The vpb_getImagesFromFolder function gets a list 'array' of the images in the directory you specify and displays to the user on the screen.
(2) vpb_getRandomImagesFromArray: This function selects an entry from the list 'array' brought by the vpb_getImagesFromFolder function at random.
The code is brief and simple, requiring only two functions: getImagesFromDir obtains . getRandomFromArray selects an entry from this array at random.
To use the script, just specify the below fields:
$directory_of_images = "photos"; //This is the directory where your images are kept on your server
$width_of_the_images = 400; //This is the width of your images
$height_of_the_images = 300; //This is the height of your images
To see the system in action, please click on the demo button below and download the script if you like what you see.