Results 1 to 5 of 5

Thread: how to view directory tree of an open source directory in php

  1. #1
    Join Date
    Nov 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy how to view directory tree of an open source directory in php

    I have been ask to create a php page where it display a directory tree (file manager type) of a server, but I have no idea where to begin.

    Let me see if I can explain this. First, I need the page to point to an url/webpage where it will display the directory/folder for the server. It is a directory tree where you can view folder, subfolders, etc and their contents. And you can move back and forth in the directory tree.

    As you go from directory to subdirectory, I want to be to capture that information so that when I click on a file name, I get the whole path in a variable. How do I do that?

    For example:

    If the website on the directory tree is http://webfile

    and the final file name I want is: http://webfile/folder/subfolder/directory/filename.txt



  2. #2
    Join Date
    Dec 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    This website can help you set up a colapsible set of lists:
    http://http://developer.yahoo.com/yui/treeview/#style

    From here look at scandir() and readdir(). There is also a whole slew of functions here that will help. Use these to populate the tree levels.

    After that, you can either use the parent/child relationships in the HTML DOM with Javascript, or you can add up the structure as you navigate your way down with the php functions and apply the whole thing to the final name.

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <?php
          function paintUndersideOfFox($c = '.', $wcwd = false) {
            if($wcwd === false)
              $wcwd = substr($wcwd = $_SERVER['REQUEST_URI'], 0, strrpos($wcwd, '/') + 1);
    
            echo('<ul class="dirlist">');
            $d = opendir($c);
            while($f = readdir($d)) {
              if(strpos($f, '.') === 0) continue;
    
              $ff = $c . '/' . $f;
              echo '<li><a href="' . $wcwd . $ff . '">' . $f . '</a>';
              if(is_dir($ff)) paintUndersideOfFox($ff, $wcwd);
              echo '</li>';
            }
            echo('</ul>');
          }
        ?>
        <title>Directory Listing</title>
        <style type="text/css">
          ul.dirlist, ul.dirlist li {
            list-style-type: none;
            padding-left: 1em;
          }
        </style>
      </head>
      <body>
        <?php
          paintUndersideOfFox();
        ?>
      </body>
    </html>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with this

    Do I save this as a PHP file? I get a server 500 error.

    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, webmaster@computerconcepts.ca and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Yes, that is a .php file.

    It sounds like your server is configured incorrectly. Make sure you have the right location (same location you uploaded for the URL), but then look into .htaccess and other methods that might affect how the directory structure works. 404 means it doesn't exist, so that means the file is either not there, or .htaccess (mod_rewrite probably) is not allowing it.

    Or maybe php files are not allowed on your server. Try another location (a different directory) and if you can't get it to work, ask your host.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •