Results 1 to 10 of 10

Thread: Directory listing display

  1. #1
    Join Date
    Sep 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Directory listing display

    Hello everyone, before I start describing my problem let me say that i searched the web for a lot of time before i decided to post my question here.
    I have a website in wich i must list and link some hundreds of files wich i have sorted in several directories. I can always use the default view of a directory listing that a browser generates when you don't have an html file, but that completly ruins the layout and you loose all acess to menus, etc, (i can't use frames). Is there a way or some script that reads the contents of a directory and displays that information (file name, date etc..) and the links to those files inside a table in a preformated html page? Maybe with options to control font size/color? and sort options by date, alphabeticcaly? If anyone knows such a script, or even a different solution to this problem please let me know. By the way, new files will be continually put on the directories from time to time.
    Thanks for reading.
    Last edited by Spacejaguar; 09-29-2005 at 01:13 PM.

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

    Default

    I can always use the default view of a directory listing that a browser generates when you don't have an html file
    The browser doesn't generate this, the server does. The easiest way to solve your problem is to edit this template.

    Failing this, you would need a server-side script:
    PHP Code:
    <?php
    $path 
    "/var/www/html/files"// Path from the server's point of view
    $browserpath "/files"// Path from the browser's point of view - no trailing slash!
    $files "<ul>\n";
    $dir opendir($path);

    while(
    $file readdir($dir)) {
      if((
    $file != ".") && ($file != "..")) {
        
    $files .= "\t<li><a href=\"$browserpath/$file\">$file</a></li>\n";
      }
    }
    closedir($dir);
    ?>
    Files in <?=$browserdir?>:
    <?=$files?>
    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!

  3. #3
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you for that code up there it works great for me , but can someone just tell me what i need to put in it to alphabetise the list???

    thank you ,

    Elaine

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Not tested, no guarantee it will work:
    PHP Code:
    <?php
    $path 
    "/var/www/html/files"// Path from the server's point of view
    $browserpath "/files"// Path from the browser's point of view - no trailing slash!
    $files "<ul>\n";
    $dir opendir($path);
    $c 0;
    while(
    $file readdir($dir)) {
      if((
    $file != ".") && ($file != "..")) {
        
    $c += 1;
      
    $filesArrA[$c] = $file;
      
    $filesArrB[$c] = $browserpath/$file;
      
    $filesArrA[$c] .= "\t<li><a href=\"$filesArrB[$c]/$filesArrA[$c]\">$filesArrA[$c]</a></li>\n";
      }
    }
    for(
    $i=0;$i<=$c;$i++){
    sort($filesArrA[$i]);
    }
    closedir($dir);
    echo 
    "Files in $browserdir<br />";
    for(
    $i=0;$i<=$c;$i++){
    echo 
    $filesArrA[$c];
    }
    ?>
    Jeremy | jfein.net

  5. #5
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    no it didnt work

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Does it show the files, or do you get an error?
    Jeremy | jfein.net

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

    Default

    Code:
    <?php
      $path = '/var/www/html/files';
      $browserpath = '/files';
    
      $files = scandir($files);
      sort($files);
    ?>
    Files in <?php echo $browserpath; ?>:
    <ul>
    <?php foreach ($files as $file): ?>
      <li>
        <a href="<?php echo $browserpath; ?>/<?php echo $file; ?>">
          <?php echo $file; ?>
        </a>
      </li>
    <?php endforeach; ?>
    </ul>
    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!

  8. #8
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

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

    Default

    Not sure I trust that. 'Different browsers have different takes on it?' Drivel, sir! It's the server that defines how that page appears, nothing more.
    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!

  10. #10
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Quote Originally Posted by Twey View Post
    Not sure I trust that. 'Different browsers have different takes on it?' Drivel, sir! It's the server that defines how that page appears, nothing more.
    The guy who wrote that blog post isn't the one who wrote the script. So take that for all it's worth.

    I don't make any claims about the script as I don't and have not used it. Just thought it was interesting.

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
  •