How can PHP be used to read and display images from a specific folder?
To read and display images from a specific folder in PHP, you can use the opendir() function to open the directory, loop through the files using readdir(), and then display the images using the <img> tag.
<?php
$dir = "images/"; // specify the directory where images are stored
if(is_dir($dir)){
if($dh = opendir($dir)){
while(($file = readdir($dh)) !== false){
if($file != "." && $file != ".."){
echo "<img src='{$dir}{$file}' alt='Image'>";
}
}
closedir($dh);
}
}
?>