# Get all the images from a folder in PHP

PHPServer Side ProgrammingProgramming

The glob function can be used to get the images from a specific folder. Below is a sample code for the same −

The path to the image folder is specified and all the files that have a .png extension are extracted. They are displayed with the help of the foreach loop −

$dir_name = "path/to/image/folder/";$images = glob($dir_name."*.png"); foreach($images as $image) { echo '<img src="'.$image.'" /><br />';
}

Based on the folder that contains all images, the path of every image present inside the folder is returned.

Published on 07-Apr-2020 11:26:02