Check if the URL is a directory before attempting to scan it

I got alot of scandir errors on files. So I changed the code a little to check if it's a directory before attempting to scan it.

Also, I just noticed your PHPDoc comment about is_dir() being unreliable. Is this still the case and if so, how can this be reproduced?