/ 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
<?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' /> "; } ?>
Comments
Subscribe to comments
You need to login to post a comment.

Hello, I can't manage to get this to work, is there a way you could help me? my page is there: bertrandclerc.com/autres/random_images/script2.php Thanks