Forum Moderators: phranque
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.
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.
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]