Script for dispalying folder contents (with links) when the file list has been disabled

Posted on 2006-03-30
Last Modified: 2010-03-04
On an appache server with the file listing ability turned off, I'd like to create an index.htm file that contains a script that would list the files in the folder.  Is this possible?  Can the file list have links to the files listed?

Question by:leslieinva
    LVL 27

    Expert Comment

    > I'd like to create an index.htm file that contains a script that would list the files in the folder.  Is this possible?

    Yes, if you have a script behind it which reads the content of the folder and generates a html page. But that script has nothing to do with apache. I'd suggest that you ask in the community support TA to move the question to the PHP or CGI Programming TA depending upon the script language you choose.

    Your DirectoryIndex directive might look like

    DirectoryIndex /cgi-bin/
    LVL 2

    Accepted Solution

    Here's a great PHP script that does this.  Just save this as index.php, upload and run!

    function dir_list($dir)
      $dl = array();
      if ($hd = opendir($dir))
        while ($sz = readdir($hd)) { if (preg_match("/^\./",$sz)==0) $dl[] = $sz;$i.=1; }
      return $dl;


    <body bgcolor="#FFFFFF" text="#000000"><table width="550" border="0" cellspacing="0" cellpadding="4">
        <td width="133"><img src="" ></td>
        <td valign="top"><b><? echo $msg ?></b><br><? echo $today;
    ?><br><b>Thought of the moment:</b><br><? echo $ts; ?></td>
    <br><hr widht="80%">

    $directory = dir("./");
    print "<b>Path:</b><font color=\"blue\">".$directory->path."</font><br>";
    print "<b>Files:</b><br>";

    print "<font color=\"blue\"><a href=$file>$file</a><br>";




    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now