View Full Version : How to make links using folder content?

12-12-2003, 07:53 PM
I have a php page that takes in a list of files (image files) from a directory and lists them. I wanted to know is there a way for me to create links using this list? Here is my code.

$dir = "testimages/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
print "$file";
print "<br>";

12-12-2003, 08:11 PM
Try changing

print "$file";


print "<a href=\"" . $file . "\">" . $file . "</a>";

12-12-2003, 08:17 PM
Thank you very much for that fast response! One currently I am accessing a folder that is in a sub directory, "/testimages". How would I access a folder that is on the same server (SUSE) but is four levels above the php page directory? I tried using ../, but didn't work.