Edit Apache mod_autoindex to preview images and mp3

3.9k views Asked by At

Is there some way to change mod_autoindex so that whenever a file of image types (jpg, png, etc.) or audio (mp3, ogg) it either opens one of those little embedded windows and shows the image or uses a flash or HTML5 based audio player to play the file. I know this module has many options for customization, but I can't figure out what code it uses to generate the file list.

1

There are 1 answers

0
Potherca On

Short Answer

Yes, there are several ways how to do this. Which one is right for you depends on your personal needs and skill-set. Your options are to either edit the C source code and create your own Apache Module, or to add extra functionality by declaring either a Client Side or Server Side script to be used as (or included from) the header of the index file.

Long Answer

Edit the Source Code

The only way to actually change the list, which is also the hardest option, would be to edit the source code and compile your own Apache Module. The HTML code for each file is put together on line 1852 in the mod_autoindex.c file. If you don't know C or if the code looks too daunting for you, there is no way to change the list directly.

You can, however, change the list indirectly by adding (either server side or client side) functionality to the index header or footer file.

Which brings us to easier options.

Add Server Side Functionality

Although you can't alter the list, you can make additions by having a server-side script that scans the directory you are browsing and adding thumbnails/previews for certain files. You could even hide the original list entirely with CSS and have the server side script build your own custom list.

Of course, you would have to be able to program Python/Perl/Ruby/PHP/etc. to do this.

I took a stab at this in PHP a while ago (mostly as an exercise) in my Apache Directory List Theming project. It doesn't do anything other than show a list of thumbnails for all of the images and PDF files in a given directory. (It's also not very sophisticated).

If you would also like to add previews for audio and/or video files, and you would like these previews to be present in the list generated by Apache, you're probably better of with a client side solution.

Add Client Side Functionality

By adding Javascript functionality, you could parse the list and for each file that is of interest to you insert a preview into the list. The prettyAutoIndex project does this. I haven't personally used it but it looks, well, pretty :-) It doesn't seem to be actively developed, but if it works it doesn't really have to be.

If its not what you want and you can code in Javascript, it shouldn't be too difficult to create something by yourself.

Wrapping up

If you decide to create a server or client side solution, it shouldn't be much more complicated than creating a file with some functionality and calling it from your Apache Config with headername:

<IfModule mod_autoindex.c>
    HeaderName /path/to/header.file
</IfModule>

Unfortunately there are some gotchas, so I would suggest taking the time to read the relevant parts of the mod_autoindex manual.