Read Images from a Directory using PHP

Basically if you have a directory in your website called “photos” that consists of one to many images (as these images can change), that I would like to read from within a PHP file into a carousel setup, i.e. something similar to this:

Hope the above makes sense, but basically want to somehow with php read total amount of images in my promo directory and then use this total in my loop max value and read each image file name in the promo directory and pass into your code

function listImages($dirname=".") {
$ext = array("jpg", "png", "jpeg", "gif");
$files = array();
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle)))
if(strstr($file, ".".$ext[$i]))
$files[] = $file;


Leave a comment