Mod-Jay Posted May 1, 2011 Share Posted May 1, 2011 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235290-directorys/ Share on other sites More sharing options...
Mod-Jay Posted May 2, 2011 Author Share Posted May 2, 2011 Help Please? Quote Link to comment https://forums.phpfreaks.com/topic/235290-directorys/#findComment-1209295 Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235290-directorys/#findComment-1209400 Share on other sites More sharing options...
Mod-Jay Posted May 3, 2011 Author Share Posted May 3, 2011 I dont know what that is, And yes i want it that way Quote Link to comment https://forums.phpfreaks.com/topic/235290-directorys/#findComment-1209712 Share on other sites More sharing options...
spiderwell Posted May 3, 2011 Share Posted May 3, 2011 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' Quote Link to comment https://forums.phpfreaks.com/topic/235290-directorys/#findComment-1209714 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.