Browse a folder...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samvb
    New Member
    • Oct 2006
    • 228

    Browse a folder...

    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

    2007/1/file1.pdf
    2007/1/file2.pdf
    2007/2/file1.pdf
    2007/2/file1.pdf


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

    Please help

    sam
  • devsusen
    New Member
    • Feb 2007
    • 136

    #2
    Hi,

    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.

    susen

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      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!

      Comment

      Working...