/ Published in: PHP
This snippet will create an array of all images in a directory and sub-directories and display them randomly.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php //path to directory to scan. i have included a wildcard for a subdirectory $directory = "images/*/"; //get all image files with a .jpg extension. $imgs = ''; // create array foreach($images as $image){ $imgs[] = "$image"; } //shuffle array //select first 20 images in randomized array //display images foreach ($imgs as $img) { echo "<img src='$img' /> "; } ?>