Jump to content

Directorys


Mod-Jay

Recommended Posts

I'm trying to make a index page to list all files and directorys, that loads the folders into another page, as if you were on a page with no index. I have the following code that did work out so well but its sorta close to what i am trying to do.

 

<?php
$dir = "../toplist/";
$files = glob($dir . '*', GLOB_NOSORT);
foreach ($files as $file) 
{
	echo"<a href='$file'>$file</a><br>";
}
?>

Link to comment
Share on other sites

Do you want it to also list files within subfolders too, for example

 

file1

file2

directory

(indent)file1

(indent)file2

(indent)file3

(indent)... etc

(indent)sub-directory

(indent)(indent)file1

(indent)(indent)file2

(indent)(indent)file3

(indent)(indent)... etc

file4

file5

...etc

 

If you do then you'll need to make a recursive function.

Link to comment
Share on other sites

a recursive function calls itself.

it works in this way, a function will open a folder, list all files and folders.

while listing, if current item is a folder, pass this folder back to the function and restart the list (this is actually a new list but becomes nested inside orgiinal list)

 

there are plenty of examples of such functions already written out there, just google something like 'file directory recursive php'

 

 

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.