cancel
Showing results for 
Search instead for 
Did you mean: 

Directory listing, IndexOptions query

mdfsnet
Dabbler
Posts: 13
Registered: ‎10-09-2008

Directory listing, IndexOptions query

How do I get an http access to a directory without an index.htm file to return a directory listing instead of 403:Forbidden. This was the default on my site before I moved it over to PAYH. I tried putting an IndexOptions line in the /.htaccess file, but with no success.
Thanks.
6 REPLIES 6
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: Directory listing, IndexOptions query

I've not used PAYH, so I don't know if it allows it, but the option in .htaccess for this is:

Options +Indexes
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Directory listing, IndexOptions query

It doesn't - probably for the best.
You could combine a rewrite in htaccess with a listing script, but that's maybe getting a bit complicated. Is it essential?
Gabe
mdfsnet
Dabbler
Posts: 13
Registered: ‎10-09-2008

Re: Directory listing, IndexOptions query

> Is it essential?
Not having auto-generated directory listings is an occasioanal pain. I have quite a few directories where I have files and previously relied on the server-generated directory listing to provide a list if contents rather than me having to write an index.htm file and, crucially, remember to update it to accurately reflect the contents of what was actually in the directory, frinstace: http://mdfs.net/temp/ which gets stuff chucked in and out frequently. The whole point of computers is for them to do things instead of humans, why should I be using my neurons creating a list of directory contents when there's a perfectly functioning server than can do all that for me with no recourse to my mental energy.
Ta.
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Directory listing, IndexOptions query

Quote from: mdfsnet
crucially, remember to update it

Shouldn't have to do that. Try a script like this. Call it anything.php and make it executable and it'll list the contents of the folder it's in. There are more elaborate ways of doing this but.
<?php
echo "<table border='1'>
<tr>
<th>Name</th>
<th>kb</th>
<th>Permissions</th>
<th>User</th>
<th>Mod date</th>
</tr>";
passthru("find . -maxdepth 1 -printf '<tr><td>%f</td><td>%k</td><td>%M</td><td>%u</td><td>%t</td></tr>'");
echo "</table>";
?>

Gabe
Ben_Brown
Grafter
Posts: 2,839
Registered: ‎13-06-2007

Re: Directory listing, IndexOptions query

That will work but personally systeming out (as passthrough does) is a bit messy, and should really be avoided. I'd use something like:

<?php
// header type stuff goes here
echo "<ul>\n";
$dir = opendir('.');
while ($file = readdir($dir))
{
  if (preg_match('/^\./', $file))
  {
    continue;
  }
  echo "\t<li><a href=\"$file\">$file</a></li>\n";
}
closedir($dir);
echo "</ul>\n";
// footer stuff here
?>

There's not as much information as your version initially but you could always combine it with stat to give the information you want.
Gabe
Grafter
Posts: 767
Registered: ‎29-10-2008

Re: Directory listing, IndexOptions query

Thinking about it  Roll_eyes (helpful if I'd done that earlier  Crazy) the system call will only work on PAYH if you're using the <a href="http://community.plus.net/forum/index.php?topic=73037.msg577649">wrapper</a> or similar. If not, you're stuck with elaborating on something like Ben's script. If you look at the use of stat <a href="http://community.plus.net/forum/index.php/topic,80496.msg655494.html#msg655494">here</a>, you'll see why I opt for the "messy" way when available.
Gabe