0

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");
?>
2
Contributors
4
Replies
9
Views
5 Years
Discussion Span
Last Post by riseguim
0

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!

1
while($entryName = readdir($myDirectory)) {
  $pathinfo = pathinfo($entryName);
  if ($pathinfo['extension'] != 'php')
    $dirArray[] = $entryName;
}
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.