How can I create a simple web page with an index of links to all files in a folder?

I need to dump a bunch of .mp3 files into a folder on my webserver to make them available to a fellow doper.

The problem is, my webserver doesn’t allow a link to a folder, and I don’t feel like coding hundreds of links to long filenames by hand.

I’ve looked around, and the best ready-made solution I could find was this perl script, which works from a list of filenames. The list could be made easily enough w/ the DOS CLI (& maybe notepad if the root directory needs to be added.)

If anyone could suggest a more elegant solution, I’d appreciate it. Otherwise, could someone hold my hand through the process of implementing this perl script?

Thanks!

I forgot–

The main reason that I would like some other approach is that the little perl script doesn’t show the size of each linked file, and I know that the fella has a dialup connection and filesize matters. (The files range from around 100k to several megs)

What I’d like is something outputs a regular index of the sort that webservers typically generate on-the-fly for folders without and index file.

Also, lest moderators worry about copyright issues, the .mp3 files aren’t music, and they are in the public domain.

Why not just upload the files and provide a link from your web page to the directory listing? It’s not elegant but it does satisfy your requirements in the short-term to provide access to the files as well as file sizes (the server does this for you).

That way, you can figure out a way to use the Perl script to generate the web page you need (with links and file sizes).

Can you set up an FTP site on your webspace? It might ultimately be the easiest way to do it for you, and faster for him.

If you’ve got php, this’ll work on apache:


<?php

if ($dir = @opendir("./")) {
  while (($file = readdir($dir)) !== false) {
$size = filesize($file);
    echo "<a href=\"$file\">$file</a> - $size bytes<br />";
  }  
  closedir($dir);
}

?>


Copy that, save it as something.php, and upload it in ASCII mode to the same directory as the mp3 files.

Here’s an example of the output in an image directory on my site:

http://neussubjex.net/reds/test.php

Ugly, but serviceable.

Duckster: My housemate, who’s the network guy, doesn’t like to allow that. I used to have apache running on my computer, and port-forwarding allowed me to link to stuff in my own folders. I reinstalled apache but it seems that port-forwarding is now disabled on the gateway, so I have to move my files over there if I want to link to them.

Black455: Thank you so much! That’s exactly what I needed, and it’s working perfectly. That’s much more like the amount of time & effort I wanted to invest in it. (ie: less than 30 seconds.)

No prob. FTR, I cribbed most of that directly from the PHP manual page on opendir() and stuck in the code to get the file size.

A year and a half ago while I was trying to learn Perl I wrote a script that does what the OP needs.

Source code available from:
http://members.rogers.com/peterorgana/html/portfolio/dir2html.html

It’s client side, the Perl script is run once and it outputs an HTML file.

The script was made to be run on a Windows machine.
I haven’t tested it under any other OS.

I was never a very good coder, and my comments are nearly illegible… enjoy? :wink:

There’s no need for a web page. Apache will automatically generate a file list for all the files in a directory if it can’t find index.htm, or index.html files ( depending on how Apache is configured ) in the directory. You must make sure also that Apache is configured to allow this type of access. For a directory, enable options indexes

http://httpd.apache.org/docs/mod/core.html#options

If you are running Microsoft IIS server, it will generate a file list automatically for directories that have no default.htm/html file. Just switch on ‘Directory Browsing’ for that directory and your set.

Dada: From what I could gather, Larry’s host disabled directory browsing via .htaccess. I suppose he could have just made a local .htaccess file, but it’s six of one, half dozen of another.

I don’t think this is a port-forwarding issue, but rather a directory permissions issue. The directory must be readable and executable by others (chmod o+rx) so that the web server can read it.