-2

I'm a basic php programmer, with a simple website with users and profile pictures.

There is a folder called ppic (profile pictures).

When I use readdir() like it says on the php.net site, it prints out two nonexistent files.

If I put a echo "there was a match - $entry<br>; inside the while loop with $entry being the file name, it prints out:

there was a match - .
there was a match - ..
there was a match - Autumn Leaves.jpg
there was a match - Creek.jpg
there was a match - Toco Toucan.jpg

I only have three files in the folder: "Autumn Leaves.jpg", "Creek.jpg", and "Toco Toucan.jpg".

I'm not too great with computers, so I have no idea what those dots mean.

Can somebody please explain these to me?

Sumit Bijvani
  • 8,154
  • 17
  • 50
  • 82
Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
  • 1
    Unix operating systems maintain a directory `.` for the current directory, and `..` for the parent directory. – Joop Eggen Oct 06 '13 at 18:18
  • Single dot "." stands for current directory and double dots ".." mean parent directory. This really doesn't have anything to do with PHP and is more of a Linux file system question. – j08691 Oct 06 '13 at 18:18
  • Why do they show up as files then? Directories aren't files. – Jonathan Lam Oct 06 '13 at 18:19
  • possible duplicate of [PHP list directories and remove .. and](http://stackoverflow.com/questions/2416137/php-list-directories-and-remove-and) or [Exclude Hidden Files from Scandir PHP](http://stackoverflow.com/q/8532569) – mario Oct 06 '13 at 18:19
  • Every directory shows up as file. In fact it historically was a file, with as binary contents a file listing, and `..` a link. – Joop Eggen Oct 06 '13 at 18:19
  • 2
    Related: [Why do directory listings contain the current (.) and parent (..) directory?](http://stackoverflow.com/q/322719/1438393) – Amal Murali Oct 06 '13 at 18:19
  • Note how the documentation's example takes this into account with `if ($entry != "." && $entry != "..")` – Boaz Oct 06 '13 at 18:20

1 Answers1

5

Learn UNIX basics: (and other common filesystem handlings)

The . is a virtual symbolic link to the current folder (e.g. ./Creek.jpg is, resolved, the same as Creek.jpg)

The .. is a virtual symbolic link to the parent folder.

To hide them, just manually exclude then via $file !== '.' && $file !== '..'.

bwoebi
  • 23,637
  • 5
  • 58
  • 79
  • 1
    [Not only Unix-like; Windows and others use them as well.](http://en.wikipedia.org/wiki/Path_\(computing\)) – Gumbo Oct 06 '13 at 18:20
  • @Gumbo: I wrote Unix, not Linux……… (and mean the unixoid systems…) – bwoebi Oct 06 '13 at 18:20