0

hey there,

I have the following piece of PHP code to retrieve a list of files on a directory, and then build links to each file:

<?php

$dir=""; // Directory where files are stored

	if ($dir_list = opendir($dir)){
		while(($filename = readdir($dir_list)) !== false){
?>

<li><a href="<?php echo $filename; ?>"><?php echo $filename;

?></a></li>

<?php
}
	closedir($dir_list);
}

?>

it is all nice and fine, but it builds two links too many. the first link leads to the folder where the php file resides, and the second link leads to the folder that contains the folder where the php file resides. I was wondering if there is a way, other than putting an if statement inside my while loop, to have php only generate links for the files on the directory I wish, excluding the other two links.

thanks in advance.

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by bibiki
0

pardon me. I solved the thread myself. for anyone wishing to know how, I included an if(!is_dir($filename)) statement after line 6, and it all worked fine.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.