If you just want a simple version :
foreach($directories as $entry) {
if (is_dir($dir_path . "/" . $entry) && !in_array($entry, array('.','..'))) {
echo "<a href=?directory=" . $dir_path . "" . $entry . "/" . "><li>" . $entry . "</li></a>";
}
else {}
}
this checks for .
/ ..
eg current dir and back dir. Regarding the spaces it sounds weird. Is it the link that is not working or is it scandir? If it is the links, replace blanks with %20, eg
$href="?directory=" . $dir_path . "" . str_replace(' ','%20',$entry) . "/";
echo "<a href='".$href.'"><li>' . $entry . '</li></a>';
more likely I think it is the lack of quotes ""
around href, eg
echo '<a href="?directory="' . $dir_path . $entry . '/' . '"><li>' . $entry . '</li></a>';
instead. When you are not adding quoutes, a link with blanks, say "test 123" will be interpreted as href=test
by the browser, because there is nothing that encapsulates the whole link. It should be href="test 123"
.