Home > Article > Backend Development > Get all images from folder in PHP
glob function can be used to get images from a specific folder. Below is the sample code for the same -
Specify the path to the images folder and extract all the files with .png extension. They are displayed with the help of foreach loop -
$dir_name = "path/to/image/folder/"; $images = glob($dir_name."*.png"); foreach($images as $image) { echo '<img src="'.$image.'" / alt="Get all images from folder in PHP" ><br />'; }
Based on the folder containing all the images, returns the path of each image present in that folder.
The above is the detailed content of Get all images from folder in PHP. For more information, please follow other related articles on the PHP Chinese website!