Forum Moderators: phranque

Message Too Old, No Replies

Directory file listings using apache modules

         

jake60

10:02 pm on Jul 11, 2008 (gmt 0)

10+ Year Member



Added as historical reference.

I have always wanted a good way to list a directory without using php or some other script. Mainly because they are normally slower than the default system. Since I have a directory with over 4,000 files a php script can take 1 1/2 minutes compared to the systems 5 seconds to display the files.

No one I have talked to knew anything about it or how to do it. So I played around and got it done.

I finally decided to look into .htaccess more closely.

All I really wanted to do was have the file name and the file size listed.

Here is the code you need to add to your .htaccess file.

<IfModule mod_autoindex.c>
IndexOptions FancyIndexing
IndexOptions SuppressHTMLPreamble
IndexOptions IgnoreCase
IndexOptions FoldersFirst
IndexOptions NameWidth=*
Indexoptions SuppressDescription
Indexoptions suppressLastModified
HeaderName header.html
ReadMeName footer.html
</ifModule>

What this code displays is the file name and the file size, period. No file description or other modified dates.

Please notice this code snipet uses a header and footer replacement.

The header html file replaces the big text of the directory path that shows up at the beginning top left of the displayed page.

The footer html file replaces the system parameters that display at the bottom of the page.

The two html files can be just simple html files that do not display anything to the screen.

In my html files I put a web site logo in the header and the
word "End" in the footer.

It is important the header and footer html files need to go in the directory you are listing.

phranque

8:48 pm on Jul 13, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], jake60!

thanks for that contribution.

jake60

10:52 pm on Jul 13, 2008 (gmt 0)

10+ Year Member



I have been around for a couple years on and off but I lost my old username and password.

I just reregistered. Now that I think about it, it might have been jake58.

g1smd

11:00 pm on Jul 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I haven't read the manual, but can you do...

<IfModule mod_autoindex.c>
IndexOptions FancyIndexing SuppressHTMLPreamble IgnoreCase FoldersFirst NameWidth=* SuppressDescription suppressLastModified
HeaderName header.html
ReadMeName footer.html
</ifModule>

and is that slightly more efficient?

jake60

11:59 pm on Jul 13, 2008 (gmt 0)

10+ Year Member



Ideally that is the way the articles say to do the indexoptions but I found it didn't work that way on my web server. Even with the + and - signs in front of them. Some say if you do not use the + or -, only the last index option in the string will be used.

Also, the namewidth=* leaves the file length as a variable. In other words it will push all the file sizes to the right past the longest filename.

you can also put a limit on the filename lengths by namewidth=60 or any number you want.

jake60

2:18 am on Jul 14, 2008 (gmt 0)

10+ Year Member



82 is a max number if you will be using 800x600 without the file sizes going off the page on the right.

105 for 1024x768 is about right.

[edited by: phranque at 6:50 am (utc) on July 14, 2008]
[edit reason] No urls, please. See TOS [webmasterworld.com] [/edit]

g1smd

8:54 am on Jul 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, I forgot you might need + in front of some of the words.

I don't do that stuff very often.