How to list the contents of a folder on a web server?

Help and discussion about non-Linux operating systems

Moderators: ChriThor, LXF moderators

How to list the contents of a folder on a web server?

Postby nitromaster » Mon Jun 11, 2007 7:42 pm

title says it all,


is this possible?
nitromaster
 
Posts: 32
Joined: Wed Feb 21, 2007 6:28 pm

RE: How to list the contents of a folder on a web server?

Postby M0PHP » Mon Jun 11, 2007 8:02 pm

If you have access to the server then it is fairly easy - just enable directory listings :)

To expand on that - if it's Apache and you do have access to the server config - just put this line in the directory configuration of the Apache config:

Code: Select all
Options Indexes


Or you could also add that very same line to a .htaccess file (in the directory you want listings of) if you don't have access to the server but are still allowed htaccess.
Image Image Image
M0PHP
LXF regular
 
Posts: 737
Joined: Wed Apr 06, 2005 7:40 am
Location: Bishop Auckland, County Durham, UK

RE: How to list the contents of a folder on a web server?

Postby JS » Wed Oct 10, 2007 4:25 pm

Alternatively, if you can't do htaccess but have PHP, then the following would work as a simple, minimal index.php:

Code: Select all
<html>
<head>
<title> PHP index lister </title>
</head>
<body>
<h1> Directory listing </h1>
<?

# Change the . below to another directory name
# if you want to list the contents of a different directory
$handle = opendir('.');

if ($handle) {
   while (false !== ($file = readdir($handle))) {
      # The if clause below is only necessary
      # if you don't want to list this file and hidden files
      # (Leaving it is a good idea)
      if (($file[0] != ".") and ($file != "index.php"))
      {
         print "<a href=\"$file\">$file</a><br />\n";
      }
   }
}
closedir($handle);
?>
</body>
</html>

I've used it (well, a slightly modified version) myself, and it works for me.
JS
LXF regular
 
Posts: 116
Joined: Wed Sep 12, 2007 11:27 pm


Return to Other OS

Who is online

Users browsing this forum: No registered users and 2 guests