Page 1 of 1

skip certain file in readdir();

Posted: Sun Jan 25, 2004 7:16 pm
by glennn3
got this readdir() function:

Code: Select all

function listfiles($directory, $select_name, $selected = "") {
   if ($dir = @opendir("/home/ensign/public_html/prose")) {
       while (($file = readdir($dir)) !== false) {
           if ($file != ".." && $file != ".") {
               $filelistї] = $file;
           }
       }
           closedir($dir);
   }
   echo "<select name="filename">";
   asort($filelist);
   while (list ($key, $val) = each ($filelist)) &#123;
       echo "<option value="$val"";
       if ($selected == $val) &#123;
           echo "selected";
       &#125;
       echo ">$val</option>";
   &#125;
   echo "</select>";
&#125;
listfiles ($key, $val);
but i need to skip one file within this dir (file.php) so that it's not returned to the select field...

anyone?

thanks
glenn

Posted: Sun Jan 25, 2004 9:53 pm
by DuFF
Easy:

Code: Select all

<?php
           if ($file != ".." && $file != "." && $file != "filename.php") {
               $filelist[] = $file;
           }
?>
Just replace "filename.php" with whatever file you don't want to include.

thanks

Posted: Sun Jan 25, 2004 10:01 pm
by glennn3
thanks, duff - you're the man.

g