?
Solved

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

Posted on 2006-03-30
2
Medium Priority
?
225 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!
0
Comment
Question by:leslieinva
2 Comments
 
LVL 27

Expert Comment

by:caterham_www
ID: 16336843
> 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
0
 
LVL 2

Accepted Solution

by:
yfedchun earned 1000 total points
ID: 16480357
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();

?>

0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

840 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