• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 298
  • Last Modified:

what are the dots when U use PHP readdir function?

hey,
when i use the readdir function to list the contents of a directory the first two listings are always '.' and '..' - can anyone explain what they are and if there is a way to exclude them from echoing ive attached the code
//code
$dir_1 = opendir("landscapes");
   while ($read_file = readdir($dir_1)) {
      echo "$read_file"."<br>";
   }
closedir($dir_1);
 
//output
.
..
600height4.jpg
600height5.jpg
600height7.jpg
adr11.jpg
adr20.jpg
adr21.jpg
adr22.jpg
baker-post-office.jpg
image.jpg
imagemountain.jpg.

Open in new window

0
nooch44
Asked:
nooch44
1 Solution
 
PhatzerCommented:
. is your current directory
.. is the previous directory

They are generally found on unix systems, as it's a way of navigating between directories.

Do this:

$excludeddirs = array('.', '..');

   while ($read_file = readdir($dir_1)) {
      if (!in_array($read_file, $excludeddirs)) {
        echo "$read_file"."<br>";
      }
   }
0
 
nooch44Author Commented:
perfect...thanks for the help
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now