We help IT Professionals succeed at work.

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

leslieinva
leslieinva asked
on
Medium Priority
239 Views
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?

Thanks!
Comment
Watch Question

Top Expert 2008

Commented:
> 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/showindex.pl
Commented:
Here's a great PHP script that does this.  Just save this as index.php, upload and run!

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

?>

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

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

while($file=$directory->read())
{
print "<font color=\"blue\"><a href=$file>$file</a><br>";
}

$directory->close();

?>

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.