• home
  • forum
  • my
  • kt
  • download
  • Show Every File/Directory in a Directory

    Author: 2008-08-22 11:12:40 From:

    You can find a demo of the script here.

    Same as usual. Open up notepad, or another text editor, and save this code as a .php file:

    QUOTE

    <html><head>
    <style type='text/css'>
    #dirlist { background: #ffffff; }
    #file { background: #f6f6f6; }
    </style>
    </head>
    <body>
    <?php
    //write to files before loading them

    //needs adding

    //function creation
    function DirList($dir,$align) {
    echo "<table align='$align' width='80%'>";
    if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
    if ($file != "." && $file != "..") {
    $link = $dir."/".$file;
    $i++;
    if(is_dir($dir."/".$file)) {
    echo "<tr><td id='dirlist' align='left'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>Directory '$link'</b></td></tr>";
    echo "<tr><td id='dirlist' align='left'>"; DirList($link,$align); echo "</td></tr>";
    continue;
    } else {
    echo "<tr><td align='left' id='file'>&nbsp;&nbsp;&nbsp;<a href=\"$link\">$link</a> - ".filesize($link)." bytes.</td></tr>";
    }
    }
    }
    if($i <= 0) {
    echo "<tr><td align='left' id='file'>&nbsp;&nbsp;&nbsp;-- Folder is empty --</td></tr>";
    }
    closedir($handle);
    }
    echo "</table>";
    }

    DirList(".","center");

    ?>
    </body>
    </html>


    Almost none of it is editable, as it creates a function. No variables are stored in the function that can be used with other purpose - functions return one value only. That value in this case is every single file and directory in the list. I also skinned it a little.

    To change the directory you are looking at, you must change this part:
    CODE
    DirList(argument0,argument1);


    argument0 - the directory you look at. "." would display every file in the current directory. "./images/" would display all files in the images folder.
    argument1 - the alignment of the display on the screen.

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      Ad Management (4)
      Calendars (3)
      Chat Systems (7)
      Content Management (6)
      Cookies and Sessions (8)
      Counters (8)
      Database Related (8)
      Date and Time (9)
      Development (6)
      Discussion Boards (7)
      E Commerce (6)
      Email Systems (9)
      Error Handling (5)
      File Manipulation (10)
      Flash and PHP (4)
      Form Processing (7)
      Guestbooks (8)
      Image Manipulation (3)
      Installing PHP (5)
      Introduction to PHP (9)
      Link Indexing (8)
      Mailing List Management (9)
      Miscellaneous (54)
      Networking (8)
      News Publishing (9)
      OOP (24)
      PEAR (6)
      PHP vs Other Languages (2)
      Polls and Voting (6)
      Postcards (1)
      Randomizing (14)
      Redirection (11)
      Searching (9)
      Security (29)
      Site Navigation (16)
      User Authentication (14)
      WAP and WML (7)
      Web Fetching (8)
      Web Traffic Analysis (15)
      XML and PHP (16)

    New

    Hot