Hi guys,

I simply need to add an exception to this directory listing coding so .php files aren't visible. Do any of you know how to do that?

Thanks!!

<?php
 // open this directory 
$myDirectory = opendir(".");

// get each entry
while($entryName = readdir($myDirectory)) {
	$dirArray[] = $entryName;
}

// close directory
closedir($myDirectory);

//	count elements in array
$indexCount	= count($dirArray);

// sort 'em
sort($dirArray);

// print 'em
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print("<TR><TH>Nom</TH><th>Type</th><th>Delete</th></TR>\n");
// loop through the array of files and print them all
for($index=0; $index < $indexCount; $index++) {
        if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files
		print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
		print("<td>");
		print(filetype($dirArray[$index]));
		print("</td>");
		print("<td><a href=\"delete.php?file=$dirArray[$index]\">Delete</a></td>");
		print("</td>");
		print("</TR>\n");
	}
}
print("</TABLE>\n");
?>

Recommended Answers

All 4 Replies

I'm not quite sure how it works... Do you think you could help me a little more, maybe show me a code line?

Thanks again your help is so very much appreciated!

while($entryName = readdir($myDirectory)) {
  $pathinfo = pathinfo($entryName);
  if ($pathinfo['extension'] != 'php')
    $dirArray[] = $entryName;
}

Thank you very much sir!

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.