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
https://forums.phpfreaks.com/topic/235290-directorys/
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
https://forums.phpfreaks.com/topic/235290-directorys/#findComment-1209400
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
https://forums.phpfreaks.com/topic/235290-directorys/#findComment-1209714
Share on other sites

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.