vantheman Posted May 2, 2009 Share Posted May 2, 2009 Hi, What's the best way to list the contents of multiple subdirectory in one list? For example: On the site, there's a "secure" folder which contains several subfolders (week_of_1-22-09, week_of_1-29-09, etc.). Each folder contains mp3 files. a.) I would like to populate a list, on the "home" page (which is not inside the 'secure' folder), that will show the Artist, Title, Genre & which folder it resides in. b.) Secondly, I would also like to be able to search by (artist, title, etc.). c.) The items on this list are for vewing ONLY (not clickable). Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/156553-list-contents/ Share on other sites More sharing options...
ignace Posted May 2, 2009 Share Posted May 2, 2009 1) and 2) can't help you with 3rd <?php function scandir_r($directory) { $scanned_files = array(); $files = scandir($directory); foreach ($files as $file) { if (is_dir($file)) { $scanned_files[] = scandir_r($file); } else { $scanned_files[] = $file; } } return $scanned_files; } function search_r($filename, $directory) { $result = array(); $files = scandir_r($directory); foreach ($files as $file) { if (is_array($file)) { $result[] = search_r($filename, $file); } else if (strpos($file, $filename) !== false) { $result[] = $file; } } return $result; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156553-list-contents/#findComment-824301 Share on other sites More sharing options...
vantheman Posted May 16, 2009 Author Share Posted May 16, 2009 I know it has been a few weeks since the reply was posted to my post. My appologies. When I test this script, it comes up as a blank page. Could it be that no particular directory is specified? If so, where/how do I specify the desired folder/subfolders to return? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/156553-list-contents/#findComment-835326 Share on other sites More sharing options...
wildteen88 Posted May 16, 2009 Share Posted May 16, 2009 All what ignace's code does is define two functions, scanddir_r and search_r. By looks of it you need to call search_r in order for the code to work. This function requires you to pass a filename and directory to search. Quote Link to comment https://forums.phpfreaks.com/topic/156553-list-contents/#findComment-835328 Share on other sites More sharing options...
vantheman Posted May 16, 2009 Author Share Posted May 16, 2009 Thanks for your response WT88, Can you give me an example of what I need to do at this point? I am a complete novice. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/156553-list-contents/#findComment-835349 Share on other sites More sharing options...
ignace Posted May 21, 2009 Share Posted May 21, 2009 <?php $found_files = search_r("somefile.ext", "/path/to/some/directory"); ?> Please note that i didn't check the code when i wrote it Quote Link to comment https://forums.phpfreaks.com/topic/156553-list-contents/#findComment-838753 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.