What are the potential pitfalls of using scandir to access folders with spaces in their path names in PHP?

When using scandir to access folders with spaces in their path names in PHP, the function may not handle the spaces correctly and can lead to errors or unexpected behavior. To solve this issue, you can use the glob function instead, which can handle spaces in file paths more effectively.

$directory = "path/to/folder with spaces";
$files = glob($directory . '/*');
foreach ($files as $file) {
    echo $file . "<br>";
}