Jump to content

listing all files, but with links


real_illusions

Recommended Posts

ok, i found the way to list all files in a directory by using this code:<?phpif ($handle = opendir('.')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "$file\n"; } } closedir($handle);}?>Only problem is, it doesn't link to them files, how do you make it do that? I've tried a quick search on google, but i couldn't seem to find anything. I dont need anything fancy, just a nice list of the files, that link to that file, preferably in a new window.:)

Link to comment
Share on other sites

<?phpif ($handle = opendir('.')) {while (false !== ($file = readdir($handle))) {if ($file != "." && $file != "..") {echo "<a href=\".\\$file\">$file</a>\n";}}closedir($handle);}?>

It looks like the dot is the directory so thats what I used. That should work anyways!

Link to comment
Share on other sites

<?phpif ($handle = opendir('.')) {while (false !== ($file = readdir($handle))) {if ($file != "." && $file != "..") {echo '<a href="' . $file . '"><br />';} closedir($handle);}?>

Untested. Might have to play with it a bit, but that would be the approach to take. If the file is not the parent or self directory, create an anchor tag followed by an html new line.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...