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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.