get all the images from a folder in php
when you want to get all image from folder then use glob()
built in function which help to get all image . But when you get all then sometime need to check that all is valid so in this case this code help you. this code will also check that it is image
$all_files = glob("mytheme/images/myimages/*.*"); for ($i=0; $i<count($all_files); $i++) { $image_name = $all_files[$i]; $supported_format = array('gif','jpg','jpeg','png'); $ext = strtolower(pathinfo($image_name, PATHINFO_EXTENSION)); if (in_array($ext, $supported_format)) { echo '<img src="'.$image_name .'" alt="'.$image_name.'" />'."<br /><br />"; } else { continue; } }
for more information