What are some best practices for automatically displaying images from a specific folder using PHP?

When displaying images from a specific folder using PHP, it's important to ensure that only image files are shown to prevent security risks. One way to achieve this is by using the `glob()` function to retrieve all image files from the folder and then loop through each file to display them on the webpage.

<?php
$folder = 'images/';
$files = glob($folder . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);

foreach ($files as $file) {
    echo '<img src="' . $file . '" alt="Image" />';
}
?>