Are there any specific file formats that should be avoided when using PHP to display images from a folder on a webpage?

When displaying images from a folder on a webpage using PHP, it is recommended to avoid using potentially harmful file formats such as .php, .html, .js, or any other executable file formats. This is to prevent any security risks such as code execution vulnerabilities. It is best to restrict the allowed file formats to only image file types such as .jpg, .png, and .gif.

$allowedFormats = ['jpg', 'jpeg', 'png', 'gif'];

$files = glob('path/to/images/*');

foreach ($files as $file) {
    $fileInfo = pathinfo($file);
    if (in_array(strtolower($fileInfo['extension']), $allowedFormats)) {
        echo '<img src="' . $file . '" alt="' . $fileInfo['filename'] . '">';
    }
}