scandir() function
<?php $directory = "images/"; $files = scandir($directory); $imageFiles = array_filter($files, function($file) use ($directory) { $filePath = $directory . $file; return is_file($filePath) && in_array(pathinfo($filePath, PATHINFO_EXTENSION), array("jpg", "jpeg", "png", "gif")); }); foreach ($imageFiles as $imageFile) { echo '<img src="' . $directory . $imageFile . '" alt="' . $imageFile . '">'; } ?>