Return to Snippet

Revision: 16035
at July 23, 2009 20:27 by superuntitled

Initial Code
//path to directory to scan. i have included a wildcard for a subdirectory
$directory = "images/*/";
//get all image files with a .jpg extension.
$images = glob("" . $directory . "*.jpg");

$imgs = '';
// create array
foreach($images as $image){ $imgs[] = "$image"; }

//shuffle array

//select first 20 images in randomized array
$imgs = array_slice($imgs, 0, 20);

//display images
foreach ($imgs as $img) {
    echo "<img src='$img' /> ";

Initial URL

Initial Description
This snippet will create an array of all images in a directory and sub-directories and display them randomly.

Initial Title
List all images from Directory (and sub-directory)

Initial Tags
php, list, image, directory

Initial Language