Rickjeh
Rickjeh

Reputation: 21

How do i remove the dots in a php directory

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); 
?>

those dots

Upvotes: 1

Views: 720

Answers (3)

Vagabond
Vagabond

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

Daniel1147
Daniel1147

Reputation: 151

add

if ($bestand == '.' || $bestand == '..')
    continue;

before the line contains echo

This code will skip iteration whenever $bestand is the dots.

Upvotes: 2

Alex
Alex

Reputation: 1

add

if(is_dir($bestand)){ continue; }

in the loop. This will skip all directories and only add files.

Upvotes: 0

Related Questions