Gamerz Posted January 29, 2010 Share Posted January 29, 2010 Hello, So I would like to display everything INSIDE a specific directory. In other words, I would like to display all file name's inside all subfolders in a specific directory. (NOT the subfolder itself...but whats inside. See example.) Example: The ROOT directory is: /root/ The directory that ALL folder's will be located is: /root/folder_names/ I have several subfolders: /root/folder_names/folder 1, /root/folder_names/folder 2, /root/folder_names/folder 3, and so on. I would like it to display all FILE NAMES in folder 1, folder 2, folder 3; but not the folders. How would I do this? Thanks so much for the help. Link to comment https://forums.phpfreaks.com/topic/190196-php-display-all-files-in-all-folders-in-a-specific-directory/ Share on other sites More sharing options...
premiso Posted January 29, 2010 Share Posted January 29, 2010 You will probably need a recursive function, but look into glob (the user comments may help was wall) and or the scandir functions. Link to comment https://forums.phpfreaks.com/topic/190196-php-display-all-files-in-all-folders-in-a-specific-directory/#findComment-1003458 Share on other sites More sharing options...
oni-kun Posted January 29, 2010 Share Posted January 29, 2010 Use the glob function. Here is an example, I've not tested it though. foreach (glob("/folder_names/", GLOB_ONLYDIR) as $dir) { $folder = explode("/", $dir); $folder = $folder[count($folder)-1]; //echo $folder . "<br />"; foreach (glob($dir . "/*", $file)) { $file = basename($file); echo "<a href='$file'>$file</a><br />"; } } Link to comment https://forums.phpfreaks.com/topic/190196-php-display-all-files-in-all-folders-in-a-specific-directory/#findComment-1003461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.