0

I have failed to find an explanation of what $user == '.' or $user == '..' means in php. I have a folder called $rooms and the code below inspects the folder for files. But I can't find a meaning to the following: if ($user == '.' || $user == '..'). I do know the two vertical lines mean 'or'. I have found this link useful but not offering a solution https://www.w3schools.com/php/php_operators.asp

$files = scandir($room);//List files and directories inside $rooms
    
foreach ($files as $user){
    if ($user == '.' || $user == '..') continue;
        $handle = fopen("$room/$user",'r');

To help I am including the full loop below $files = scandir($room);//List files and directories inside $rooms

foreach ($files as $user){
    if ($user == '.' || $user == '..') continue;
        $handle = fopen("$room/$user",'r');
        $time = fread($handle, filesize("$room/$user"));
        fclose($handle);
    if ((time()-$time)>20) unlink("$room/$user");
}
  • 2
    In PHP? Nothing. For linux filesystems? `.` is the current directory and `..` is the parent directory. – Sammitch Nov 04 '21 at 20:25
  • Seems like file system is being used as a database. See first user contribution on https://www.php.net/manual/en/function.scandir.php and you don't need that conditional at all. – user3783243 Nov 04 '21 at 20:31
  • I did not know until now that if I can't find an answer for a php issues I should consider trying searching the same instruction as a possibly a Linux issue. Searching with the Linux keyword instead of the Php word. I will leave the question stand even though it has already been answered as a Linux question. – Charles Haughey Nov 04 '21 at 21:13

1 Answers1

2

On linux if you list any directory, the listing will always include a pseudo-file . and ... The single . is the current directory, so you can for example execute ls . and it will list the contents of the current directory. The two dots .. means 'the directory above this one', so ls .. will list the contents of the parent directory.

This script ignores these pseudo/fake files since it is only interested in real files

Dylan Reimerink
  • 5,874
  • 2
  • 15
  • 21