Re: [PHP] Directory Walking From: Hans H. Anderson (me <email protected>)
Date: 08/15/00

Alex,

This was just a quick and dirty attempt, but it seems to work. Maybe it
can help you get to where you want:

----
<?php

if(!isset($dir)) $dir = "/home/hans/www/clients/solplex/htdocs";

if(ereg("\.{2,2}$",$dir)) { $fix = explode("/",$dir); $c = count($fix); // could use array_splice here, if using version of PHP with it unset($fix[$c-1]); unset($fix[$c-2]); $dir = implode("/",$fix); }

print "<b>$dir</b><br><br>";

$d = opendir($dir);

while($f = readdir($d)) { if(is_dir($f)) print "<a href=\"$PHP_SELF?dir=" . urlencode($dir . "/$f") . "\">$f</a><br>\n"; } closedir($d);

?>

----

On Tue, 15 Aug 2000, Alex Augot wrote:

> Hi ya, > > I've been working on an automatic page generator for the intranet > system in the company I work for. The system basically just allows > you to toss in your name, e-mail, some other information, and some HTML > It will then just use some templates and output some nicely formatted > HTML with the company letterhead on it. > > In the current version it can only save to one directory, which is > annoying. > In the newer version I'm working on, I'm trying to make it walk up and > down directory's, and list the directory contents in a option box. It > will work > fine for the home directory, and one directory above home. After that, > it dies. > > I talked to the local PHP guy, and he was sort of stumped too... Here's > some > snippets of the code... > > <FORM ACTION="generate_test.php3" METHOD="GET"> > <SELECT NAME="requested_dir" SIZE="1"> > <?php > if(!isset($requested_dir)) { $requested_dir = "."; } > $current_directory = opendir($requested_dir); > while ($entry_name = readdir($current_directory)) > { > if(is_dir($entry_name)) > { > print("<option>$entry_name</option>\n"); > } > } > print("</SELECT>\n"); > print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n"); > ?> > <INPUT TYPE="SUBMIT" VALUE="Change Dir"> > </form> > > That will generate the following HTML output > > <FORM ACTION="generate_test.php3" METHOD="GET"> > <SELECT NAME="requested_dir" SIZE="1"> > <option>.</option> > <option>..</option> > <option>testing</option> > <option>testing.period</option> > </SELECT> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; > <INPUT TYPE="SUBMIT" VALUE="Change Dir"> > </form> > > In a nutshell, what I want the script to do, is know what directory it > is in. > If you click "..", it should go up to a higher level. I'll have to > define a global > variable or something, but I'm not sure. Anyone have any ideas? > > -- > Alex Augot ex.3065 > Software Process Engineering Group > Teradyne, Inc > Phone: 617-422-3065 > Cell: 617-435-7035 > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe <email protected> > For additional commands, e-mail: php-general-help <email protected> > To contact the list administrators, e-mail: php-list-admin <email protected> > > >

Hans Anderson ~ me <email protected> PO Box 426, Missoula, MT 59806 | PHP, Search Engines, SQL (800)397-9116 / (406)549-6524 | Databases, Flash Multimedia, http://www.hansanderson.com | Killer Audio Production, http://www.goofiness.com | Minty Fresh Breath.

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>