Re: code quest

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

 



Daniel, this is so close to bang on it's unbelivable. Only prob is my host provided me with this $^@&%^^$&! dir which is named .smileys, which holds icons for use in the control panel. It should NOT list it, nor list the /cgi-bin, nor /images. Can it somehow exclude those 3, or maybe a list of things not to notice?

Also, how compatible is it with SSI includes? If part of the echo is an ssi include statement, will it work right? Hmmm...



Daniel P. Brown wrote:
On Fri, Nov 26, 2010 at 19:03, Kirk Bailey <kbailey@xxxxxxxxxxxxxxxx> wrote:
I need a routine that will return a list of every directory immediately
under the current directory- but nothing else, just a list of directories, 1
level deep, NO FILES, no listing of current dir or prior dir either.

    Simple:

    <?php

    $ls = scandir(dirname(__FILE__));

    foreach ($ls as $d) {
        if (is_dir($d) && $d != '.' && $d != '..') {
            echo '<a href="'.$d.'">'.$d.'</a><br/>'.PHP_EOL;
        }
    }
    ?>

   If you want something more powerful - and often quicker - check
into SPL: specifically FilesystemIterator[1], DirectoryIterator[2],
and RecursiveDirectoryIterator[3].  A quick example to link all child
files and directories with relative linking:

    <?php

    $path = dirname(__FILE__);
    $list = new RecursiveIteratorIterator(new
RecursiveDirectoryIterator($path));

    foreach ($list as $k => $v) {
        if (!preg_match('/\./',$v)) {
            $v = str_replace($path.'/',null,$v); // We only want
relative linking
            echo '<a href="'.$v.'">'.$v.'</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