Monday, 7 January 2013

Display Random Images using PHP

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 which 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.

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

Display Random Images using PHP

Click here to view this tutorial