+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP Directory Listing Script

  1. #1
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15

    PHP Directory Listing Script

    I had this problem at work that I completely forgot about. I left one of our production servers directory listings available to all who viewed it, which is a complete no-no. So I wrote this small script that you can name whatever you want and place it in any directory and it will link all your scripts. That way you can directly link to the script and get the same view of a file system without showing all your files and folders if you are missing an index page

    PHP Code:
    <?php


    $dirlisting 
    directory_display();
    sort($dirlisting);

    foreach (
    $dirlisting as $file)
    {
        if (
    filetype($file) == 'dir')
        {
            echo 
    "<tr>\n<td><img src=\"./images/folder.png\" /></td>\n</tr>\n";
        }
        else
        {
            echo 
    "<tr>\n<td><img src=\"./images/file-generic.png\" /></td>\n</tr>\n";
        }
        echo 
    "<tr>\n<td>\n<a href=\"$file\">$file</a></td>\n</tr>\n<br />";
    }


    function 
    directory_display()
    {

        
    $directory opendir(".");

        
    //while ($file = readdir($directory))
        
    while (false !== ($file readdir($directory)))
        {
            if (
    $file != "." && $file != "..")
            {
                
    $dirlisting[] = $file;
            }
        }
        
    closedir($directory);
        return 
    $dirlisting;
    }
    ?>
    The two images for the folders are attached to place in an "/image" folder
    Attached Images    

  2. #2
    hemmeter is offline Junior Member
    Join Date
    May 2008
    Posts
    12
    Nice little script.

    FYI, you should always add the following to your .htaccess file so that your directories are never shown by the web server. This only works on Apache, but that's what most use.

    Options -Indexes

  3. #3
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    Your correct Scott about the addition to your .htaccess, but in my case, our Sysadmins will not turn .htaccess on

+ Reply to Thread

LinkBacks (?)

  1. Hits: 1
    01-22-2010, 02:56 PM
  2. Hits: 1
    01-11-2010, 11:15 AM

Tags for this Thread

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

SEO by vBSEO 3.5.1