PHP – Display random images from a directory.

This is a small script made by me to display random images from a directory. The directory is supposed to be provided by the user.
Before we take a look at the programs, I want to list the functions that i have used in the script.

This functions scans a directory and returns the list which contains all the files present in the directory.

This function returns the information of the specified file in the parameter. This function plays an important role in this script as it helps us separating image files from other files.

Feel free to use this script in your websites but do not forget to modify the following variables:
$imageDirectory – This variable specifies the directory from which you wish to display random images.
$image_ext – Edit this array to add new image extensions or remove existing image extensions.

Live Demo.
Hope you enjoyed the post!

The following two tabs change content below.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">