Re: code quest
| From: | Kirk Bailey | Date: | Thu, 02 Dec 2010 03:43:11 +0000 |
| Subject: | Re: code quest | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309808@lists.php.net to get a copy of this message | ||
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@howlermonkey.net> wrote:-- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-----+ | BOX | +-----+ thinkI 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(newRecursiveDirectoryIterator($path));foreach ($list as $k => $v) { if (!preg_match('/\./',$v)) { $v = str_replace($path.'/',null,$v); // We only wantrelative linkingecho '<a href="'.$v.'">'.$v.'</a><br/>'.PHP_EOL; } } ?>