Jump to content

scandir()


Cronthenoob

Recommended Posts

Ok i've got this:

 <HTML> <HEAD> </HEAD> <BODY><?phpif ($handle = opendir('.')) {  while (false !== ($file = readdir($handle)))  {   if ($file != "." && $file != ".." && $file != "index.htm"	 && $file != "listfile.php")	   echo "<a href=\"$file\">$file</a><br>";  }  closedir($handle);}?> </BODY></HTML>

That will get all of the files in the directory and spit them out on the page.How can I exclude the file index.php from the list, and is there an easier way to do this than putting that index.php in every single folder?I also want to add a breadcrumbs navigtion at the top, and I have no idea how I would go about doing that.

Link to comment
Share on other sites

So you want to exclude index.php from showing or do you want it deleted or what? you if with the filenames should exclude it from echoing out so you shouldnt have a problem!

Link to comment
Share on other sites

You shouldnt have to. I dont see why you would have to anyways. if you put in your if statement another "$file = "index.php" " it should work, so if it isnt index.php it will display. What problems are you having anyways?

Link to comment
Share on other sites

It only works If I have the file in every directory and subdirectory.so if i have a folder called "images" with a folder called "good" and a folder called "bad" inside "images"I would have to put the file in the "images", "good", and "bad" folders in order to display everything in all of the folders.My question is:How can I make it so that I don't have to put a copy of the php file in every single folder?

Link to comment
Share on other sites

You are telling opendir to read the current folder:if ($handle = opendir('.')) {You need to use is_dir to detect if $file is a directory, and, if it is, have it link to the index page with the folder name in the querystring. Then open that folder with opendir.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...