Re: code quest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



my current code is as follows:

   *<ul>
   <?php # The next several lines declare an array of directories which
   are NOT to be listed!
   $excludes[] = 'images';
   $excludes[] = 'cgi-bin';
   $excludes[] = 'vti_cnf';
   $excludes[] = 'private';
   $excludes[] = 'thumbnail';

   $ls = scandir(dirname(__FILE__));
   foreach ($ls as $d) {
     if (is_dir($d) && !preg_match('/^\./',basename($d)) &&
   !in_array(basename($d),$excludes)) {
         echo '<li><a href="'.$d.'">'.$d.'</a><br/>'.PHP_EOL;
     }
   }
   ?>
   </ul>*

The page containing this is at this url:
   http://www.howlermonkey.net/dirlisting.php
I believe this will be a starting point for the functionality I am looking for- an automatic menu of areas in a website one may go to. By excluding some folders, people don't go trespassing into the cgi-bin or images folder, or into areas reserved for administrative uses.


Daniel P. Brown wrote:
On Wed, Dec 1, 2010 at 23:13, Kirk Bailey <kbailey@xxxxxxxxxxxxxxxx> wrote:
[snip!]
Can this be improved to exclude anything with a '.' or a '-' in it's name?
This will exclude the smileys and cgi-bin and such. If it can be persuaded
to read a 1 line description from each subdirectory it could then use THAT
as the text in the link, instead of the name. This could be useful in many
settings.

    Sure.  Change:

        if (is_dir($d) && $d != '.' && $d != '..') {

    To:

        if (is_dir($d) && !preg_match('/[\.\-]/',$d)) {

    Keep in mind, though, that the change will no longer show anything
that matches the below either:

        example.directory
        example-directory
        special-images
        css.files

    In other words, you may instead want to explicitly state which
directories to omit, and then drop anything that begins with a dot as
well (hidden directories on *NIX-like boxes) like so:

<?php
$excludes[] = 'cgi-bin';
$excludes[] = 'vti_cnf';
$excludes[] = 'private';
$excludes[] = 'thumbnail';

$ls = scandir(dirname(__FILE__));
foreach ($ls as $d) {
  if (is_dir($d) && !preg_match('/^\./',basename($d)) &&
!in_array(basename($d),$excludes)) {
      echo '<li><a href="'.$d.'">'.$d.'</a><br/>'.PHP_EOL;
  }
}
?>


--
end

Very Truly yours,
                - Kirk Bailey,
                  Largo Florida

kniht +-----+ | BOX | +-----+ think

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux