How can the user modify the PHP script to only display a specific type of file, such as *.jpg files?

To only display a specific type of file, such as *.jpg files, the user can modify the PHP script by adding a conditional check to filter out files that do not have the desired file extension. This can be done by using the pathinfo() function to get the file extension and then comparing it to the desired extension, in this case, ".jpg".

<?php
$dir = "path/to/directory";

$files = scandir($dir);

foreach($files as $file) {
    if(is_file($dir . '/' . $file) && pathinfo($file, PATHINFO_EXTENSION) == 'jpg') {
        echo $file . "<br>";
    }
}
?>