Home >Backend Development >PHP Tutorial >Get all images from folder in PHP

Get all images from folder in PHP

WBOY
WBOYforward
2023-08-27 23:25:111369browse

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 &#39;<img  src="&#39;.$image.&#39;" / alt="Get all images from folder in PHP" ><br />&#39;;
}

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete