tags:

views:

53

answers:

4

We use an apache server that does not allow directory listing.

There is a specific directory I would like to allow listing of.

How can make a simple HTML file that will contain the contents of this directory?

+1  A: 

This can't be done with pure HTML.

However if you have access to PHP on the Apache server (you tagged the post "apache") it can be done easilly - se the PHP glob function. If not - you might try Server Side Include - it's an Apache thing, and I don't know much about it.

mbanzon
I've never wrote PHP. If you could give a working example for an HTML I can put in my dir - it would be great!
David B
+1  A: 

You can either: Write a server-side script page like PHP, JSP, ASP.net etc to generate this HTML dynamically

or

Setup the web-server that you are using (e.g. Apache) to do exactly that automatically for directories that doesn't contain welcome-page (e.g. index.html)

Specifically in apache read more here: Edit the httpd.conf: http://justlinux.com/forum/showthread.php?s=&postid=502789#post502789

or add the autoindex mod: http://httpd.apache.org/docs/current/mod/mod_autoindex.html

MrOhad
The apache server is out of my control. `.htaccess` is disabled. I'm a real newbie to this, so a simple working example would be appreciated.
David B
does your apache support PHP? you must use apache that supports server-side scriptwriting otherwise it's impossible..
MrOhad
@MrOhad How can I tell?
David B
add some php file like hello.php, edit this file: "<?php Print "Hello, World!";?> " , try to access it from the client http://server/hello.php and see what you get..
MrOhad
@MrOhad This works. So what should I pout in the HTML to allow listing?
David B
put index.php file on each directory, you can find code that do that here: http://www.zwixy.com/list_files_in_folder.php or http://www.velocityreviews.com/forums/t237393-list-files-from-directory-on-a-site.html it's an ugly workaround...
MrOhad
A: 

Did you try to allow it for this directory via .htaccess?

Options +Indexes

I use this for some of my directories where directory listing is disabled by my provider

Michael
That was my first choice, but the apache server is out of my control and it seems `.htaccess` is disabled. I get `Internal Server Error` when adding such `.htaccess`.
David B
A: 

For me PHP is the easiest way to do it:

<?php

echo "Here are our files";

$path = ".";

$dh = opendir($path);

$i=1;

while (($file = readdir($dh)) !== false) { if($file != "." && $file != ".." && $file != "index.php" && $file != ".htaccess" && $file != "error_log" && $file != "cgi-bin") {

    echo "<a href='$path/$file'>$file</a><br /><br />";
    $i++;
}

}

closedir($dh);

?>

Place this in your directory and set where you want it to search on the $path. The first if statement will hide your php file and .htaccess and the error log. It will then display the output with a link. This is very simple code and easy to edit.

hart1994