Jump to content

Listing files from a directory


abhi_madhani

Recommended Posts

Hi friends,

 

I took this script from php.net that lists a name of file from a specified directory.

 

	$path = "./files/";
if ($handle = opendir($path)) 
{
# 
while (false !== ($file = readdir($handle)))
{
	if ($file != "." && $file != "..")
	{
		$thelist .= '<a href="'.$file.'">'.$file.'</a>';
	}
}
closedir($handle);
}

 

can someone please shed off some light as to how this line of code is processed, and what it means.

 

while (false !== ($file = readdir($handle)))

 

Regards,

Abhishek

Link to comment
https://forums.phpfreaks.com/topic/197497-listing-files-from-a-directory/
Share on other sites

this part carries an implicit value of TRUE as long as there are more files

  ($file = readdir($handle))

Once there are no more files, the implicit value is now FALSE

so the !==  is saying to the "WHILE' - when the implict value become FALSE stop looping 


 

Make sense?

  Quote

Thanks for all your help.

 

I am really grateful to you people.

 

I am using this code, as I found it on php.net, but sooner or later I will try scandir() function to list file.

 

Thanks again.

 

if you really want a file lister you can try my sitemap code.

http://files.tazerenix-productions.com/sitemap/sitemap.zip

http://files.tazerenix-productions.com/sitemap/sitemap.php

Although its probably better to code your own as you would learn a lot more

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.