How to get all images from specific directory.Like $Dir = 'images/marriage/';
Result
<img src="img1.png">
<img src="img2.png">
<img src="img3.png">
<img src="img4.png">
<img src="img5.png">
Try this code. Put the file containing the code in the directory that contains the "images" directory
<?php
$dir = "images/marriage/";
$files = scandir($dir);
Foreach($files as $filename){
echo "<img src='".$dir."$filename'><br/>";
}
?>
You could have attempted something, but:
foreach(glob($Dir.'*.*') as $name) {
//echo your img using $name
}
or *.jpg
or whatever, or lookup glob()
.
foreach (scandir($Dir) as $img) {
if ($img[0] != '.') print '<img src="' . $img . '">';
}