Removing periods in directory listing..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
seeker2921
Forum Contributor
Posts: 120
Joined: Sat Mar 22, 2003 7:10 pm
Location: Wiesbaden Germany
Contact:

Removing periods in directory listing..

Post by seeker2921 »

You know when you view a directory how it looks like this:

.
..
fileone.php
filetwo.php

Well? Using the script below how would I remove the . and .. from showing up on the page with all my other files.. I tried adding them to the exclude array but it didn't work..

Code: Select all

<? 
$maindir = "." ; 
$mydir = opendir($maindir) ; 
$exclude = array( "index.php") ; 
while($fn = readdir($mydir)) { 
if ($fn == $exclude[0] || $fn == $exclude[1]) continue; 
echo "<br><a href='$fn'>$fn</a>"; 
} 
closedir($mydir); 
?>
thanks!
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

Try:

Code: Select all

<?
$maindir = "." ;
$mydir = opendir($maindir) ;
$exclude = array( "index.php", "..", ".") ;
while($fn = readdir($mydir)) {
  if (!in_array($fn, $exclude)) {
    echo "<br><a href='$fn'>$fn</a>";
  }
}
closedir($mydir);
?>
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Code: Select all

<?
$maindir = "." ;
$mydir = opendir($maindir) ;
while($fn = readdir($mydir)) {
if ($fn != "index.php" && $fn != "." && $fn != ".."){
echo "<br><a href='$fn'>$fn</a>";
}
}
closedir($mydir);
?>
Post Reply