What are some common mistakes or errors to watch out for when using PHP to display images from a folder on a webpage?

One common mistake when displaying images from a folder using PHP is not properly handling file paths. Make sure to use the correct file path and ensure that the images are accessible to the PHP script. Additionally, be cautious of using user input directly in file paths to prevent security vulnerabilities.

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

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