What potential issues can arise when listing all files in a directory using PHP, especially when dealing with hidden files?

When listing all files in a directory using PHP, one potential issue is that hidden files (files starting with a dot) may also be displayed, which can clutter the output and potentially expose sensitive information. To solve this issue, you can filter out hidden files by checking if the filename does not start with a dot before displaying it.

$directory = '/path/to/directory/';

$files = scandir($directory);
foreach ($files as $file) {
    if ($file[0] !== '.') {
        echo $file . "<br>";
    }
}