Click to See Complete Forum and Search --> : I want to open a directory structure...


Anon
09-29-2000, 11:42 PM
how do I list directories as hyperlinks, then when clicking on them, branching out the files...

also, can I do a page count in a directory? .. meaning can I count the number of pages/files in each directory? ...

thanks in advance.
-eyal.

Anon
09-30-2000, 12:50 AM
Here is the code that I use in a log file import script that I run...

<%

if (strlen("$QUERY_STRING")==0){
$diropen="/opt/data/pxlog";
}
else {
$r=split("=","$QUERY_STRING");
$diropen=$r[1];

}
print "<h1>Import Data from $diropen</h1><p>&nbsp;</p><p>&nbsp;</p>";

if ($r[0]=="dir" || $diropen=="/opt/data/pxlog"){
if (chdir("$diropen")){
$d=dir('.');
while ($what=$d->read()){
if (is_dir($what)){
$f=getcwd();
print "<a href='import.php?dir=$f/$what'>$what</a><br>";
}
else {
$f=getcwd();
print "<a href='importlog.php?file=$f/$what'>$what</a> ".filesize($f.'/'.$what;
}
}
}
}




%>


Hope this helps!

- Kevin

Anon
09-30-2000, 04:14 PM
thanks a lot!!! ...


I modified it a bit.. so it works in any directory ... and I also got it to organize better...

check it out ..




---------------------------------------------

<head>
<title>Untitled</title>
</head>

<body>
<ul>
<?

if (strlen("$QUERY_STRING")==0){
$diropen=".";
}
else {
$r=split("=","$QUERY_STRING");
$diropen=$r[1];

}
print "<li><h1>Import Data from $diropen</h1></li>";

if ($r[0]=="dir" || $diropen=="."){
if (chdir("$diropen")){
$d=dir('.');
while ($what=$d->read()){
if (is_dir($what)){
$f=getcwd();
print "<li><a href='$PHP_SELF?dir=$f/$what'><FONT COLOR=RED SIZE=3><B>$what</B></FONT></a></li>";
}
else {
$f=getcwd();
print "<li><a href='$PHP_SELF?file=$f/$what'>$what</a></li>
".filesize($f.'/'.$what);
}
}
}
}




?>
--------------------------------------

ps.
I forgot all about the <? ?> ... and the <% %> .... and I freaked out when the code was printed in the src code ... lol ;-)


have fun with it!

Anon
09-30-2000, 08:30 PM
or actual ... for the code to show up here in the web form ... try this code ...

-------------------


<head>
<title>Untitled</title>
</head>

<body>
&lt;ul&gt;

<?

if (strlen("$QUERY_STRING")==0){
$diropen=".";
}
else {
$r=split("=","$QUERY_STRING");
$diropen=$r[1];

}
print "&lt;li&gt;<h1>Import Data from $diropen</h1>&lt;/li&gt;";

if ($r[0]=="dir" || $diropen=="."){
if (chdir("$diropen")){
$d=dir('.');
while ($what=$d->read()){
if (is_dir($what)){
$f=getcwd();
print "&lt;li&gt;<a href='$PHP_SELF?dir=$f/$what'>&lt;FONT COLOR=RED SIZE=3&gth;&lt;B&gt;$what&lt;/B&gt;&lt;/FONT&gt;</a>&lt;/liNgt;";
}
else {
$f=getcwd();
print "&lt;li&gt;<a href='$PHP_SELF?file=$f/$what'>$what</a>&lt;/li&gt;
".filesize($f.'/'.$what);
}
}
}
}




?>




</body>

-------------------------


hope I got all of them ...
(just incase i didn't:

I used &lt;UL&gt; to start an Unorderd List
then I added a &lt;LI&gt; - Line for each print function...

dressed it up with a few font features; &lt;B&gt; and &lt;FONT&gt; ... and vuala! )

-enjoy!