How to list images in directory with php

An easy way to get images from a directory using php:

//path to directory to scan
$directory = dirname(dirname(__FILE__)) . '/my_image_dir/';

//get all image files with a .jpg, gif and png extension.
$images = glob($directory . "*.{jpg,gif,png}", GLOB_BRACE);

//print each file name
foreach ($images as $image) {
    echo basename($image) . "
";
}

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.