Reputation: 21
I have a code that shows dots in the directory. I'm trying to get rid of them but google doesn't help, those dots mean back and localhost and the dots need to be removed how do i do this?
<?php
$map = opendir('file');
while ($bestand = readdir($map))
{
echo "<a href='file/$bestand'>$bestand</a><br/>";
}
closedir($map);
?>
Upvotes: 1
Views: 720
Reputation: 897
Referring to the manual at php.net and adding to HungHsuan Wei's answer.
<?php
if ($map = opendir('file')) {
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($map))) {
if($bestand == '.' || $bestand == '..')
continue;
}
closedir($handle);
}
Upvotes: 0
Reputation: 151
add
if ($bestand == '.' || $bestand == '..')
continue;
before the line contains echo
This code will skip iteration whenever $bestand is the dots.
Upvotes: 2
Reputation: 1
add
if(is_dir($bestand)){ continue; }
in the loop. This will skip all directories and only add files.
Upvotes: 0