PDA

View Full Version : PHP directory list creating hyperlinks



JoshuaR
July 14th, 2008, 10:28 PM
Hi,
I was wondering if anyone knows a way to do the following?
I'm looking to make a php page that creates a listing of files based on the content of a directory on the same server, and also formats the list so that when it is displayed, the list of files are hyperlinks to the files themselves.

What I'm trying to do is just have a download page so that people can download files from the website; but I need it so that my people uploading the files won't have to edit any code or anything--that's why I'm trying to get the list created automatically by what the directory contains.

I hope that makes sense. Thanks for the help. :)

JoshuaR
July 17th, 2008, 12:00 AM
No ideas?

It doesn't have to be PHP if that helps...

simplistik
July 20th, 2008, 10:47 AM
<?php
$path = "/full/path/to/files";
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$files .= '<a href="'.$file.'">'.$file.'</a>';
}
}
closedir($handle);
}
?>


http://us.php.net/function.opendir

JoshuaR
July 20th, 2008, 08:37 PM
Awesome mate, thanks for that. :hugegrin:

I've been looking around and I also found this (see attachment) if anyone is interested...

saxx
July 20th, 2008, 08:43 PM
you could just no create an index page on your server :D

if your having problems with opendir, look at scandir too.

JoshuaR
July 21st, 2008, 03:46 AM
you could just no create an index page on your server :D
yeah I thought about that...but I can't format the page that way...and I gotta make it look good ;)