...

View Full Version : a script to fill a page with links to all the files in the folder



baguiomaster
06-10-2007, 02:08 PM
Is there a script that will automatically fill a webpage with links to all of the files in its web directory (except for itself)? It would sure be handy so all the resources (regardless of how the content changes) in a folder can be easily accessed.

Appreciate anything the geniuses can come up with! :)

CFMaBiSmAd
06-10-2007, 03:22 PM
Because javascript does not have direct access to or have the ability to do a directly listing of files on a web server, you need to do this using a server side scripting language (PHP/ASP/ASP.NET...)

baguiomaster
06-10-2007, 05:34 PM
Oh. :-( Any suggestions on how I would do this with PHP then?

Vladdy
06-10-2007, 06:39 PM
Because javascript does not have direct access to or have the ability to do a directly listing of files on a web server, you need to do this using a server side scripting language (PHP/ASP/ASP.NET...)

Not entirely correct.

If you configure your server to allow the folder listing access (on apache it is as simple as adding the following line to .htaccess: "Options +Indexes +MultiViews +FollowSymlinks"), you can use the XMLHTTPRequest to get the html file returned by the server and then parse it to extract desired file information.

smokingmirror
06-10-2007, 09:15 PM
I don't know if it will be of use in your case, but I've written a few websites which use a PHP script to list the contents of a folder as active links. I use the following code in a file called index.php, and put it into the folder in question. Here's the code:


<html>
<head>
</head>
<body>
<?

//define the path as relative
$path = ".";

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

//running the while loop
while ($file = readdir($dir_handle))
{
if($file!="." && $file!=".." && $file!="index.php")
echo "<a href='$file'>$file</a><br/>";
}

//closing the directory
closedir($dir_handle);

?>
</body>
</html>

baguiomaster
06-12-2007, 12:15 PM
Hmmm, that looks like it might work! :)

thanks!! :thumbsup:

baguiomaster
06-14-2007, 11:20 AM
works like a charm!!! :-):thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum