Listing the contents on a web server without listing directories

I seem to require this snippet of code quite often.

This PHP code will list the contents of a web server’s directory. It will list only files, and not directories (so it’ll skip the parent directory link which shows up by default on most Apache Index files).

if ($handle = opendir('.')) {
	while (false !== ($file = readdir($handle))) {
		if ($file != "index.php" && strncmp($file, ".", 1) != 0) {
			echo "<li><a>" . $file . "</a></li>\n";

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s