Is it possible to display folder contents, automatically as hyperlinks on a web page.

I have a folder on our server which we wish to keep adding and removing files from, and would like a web page with hyperlinks to each file. Rather than editing the web page each time we change the folder contents, is it possible to automate this process?

Regards, Thanks, DaveB

Recommended Answers

All 2 Replies

If you leave the index.html page out of a folder, on some servers, with some configurations, it does that for you.

Admitadly, you might not want the default index page (it's ugly ), or your server might not support it, or it might be disabled.

The most controllable way would be to write a little server-side script to do it. What scripting languages do you have access to on the server? What's the server OS aswell? And the server application?

If you have a Linux+Apache server ( or some other combinations, include Windows+IIS with the right settings ), and you can use Perl; something as simple as this would work:

print "Content-Type: text/html\n\n";
print "<html><head><title>Directory Index</title></head><body>\n";
print "<h1>All of the files in this folder:</h1>\n";
foreach( glob( "*.*" ) )
	print "<a href=\"$_\">$_</a><br/>\n";
print "</body></html>\n";

Save as "", upload it, and give it execute permission ( linux chmod 755 ).. You'd also need to configure the server to treat files as directory indexes. Honestly, without knowing server OS and server application though.. I don't think I'm being that helpful.

If you only have access to PHP.. er, I can't bring myself to write in a language that ugly, but, it's equally easy.

This isn't an HTML/CSS question... but don't worry, its not a specific server lang question either.

May seem odd.... but why not use the Account control system - I'm assuming that you have something like CPanel or such - thet usually has a file manager.
Alternatively, there are scripts around to act as little "Libraries" for such things.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.