By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,357 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

Browse a folder...

P: 228
hi guys,....

I am trying to browse a folder located directly under htdocs. The folder, say called 2007 got 6 subfolders inside it, named 1-6. Each of this subfolders got 2 files each. I need to list the files, creating a link to each file like this


...........How Can I pass the starting folder ie. 2007 then the recursion goes on?

Please help

Apr 28 '07 #1
Share this Question
Share on Google+
2 Replies

P: 136

this will be a big code. u need to know Directory functions and File System functions for this purpose. Please go through this sections in php. Try to develop the code. If u then have some problem or bugs, we will certainly help u out for that.

Apr 28 '07 #2

Expert 5K+
P: 5,821
Traversing through the directory structure is easy enough. Just use PHP's is_dir function and then create a new directory handler to traverse that directory.

Of course, if you want to also create a link to that file, you've got some complications to deal with. Namely, how do you keep track of which directory each directory handle is working with?

If you said, "Well, I'll just create an array and push the directory name onto it when I create a new handle and pop it off when I delete the handle," then you're not thinking OOP.

My suggestion for approaching this situation is to create your own Directory class and use it to recursively traverse your filesystem.

Make sure you include a maximum depth and an option not to follow symlinks!

And don't forget to save it in your custom frameworks directory so that you can take it with you on other projects, too!
Apr 28 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.