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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.