Re: Help on Opening dir by clicking (Urgent!!!)
| From: | Jason Lavigne | Date: | Fri, 08 Dec 2000 02:27:12 +0000 |
| Subject: | Re: Help on Opening dir by clicking (Urgent!!!) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-29134@lists.php.net to get a copy of this message | ||
Here, try this. There are two parts. You could change the "$file_list[] ="
lines to echo or print.
$dir_root = "/your/dir";
$handle=opendir($dir_root);
while (($fil = readdir($handle))!==false) {
if(!is_dir($fil)) {
if($fil !="." & $fil !="..") {
$file_list[] = $fil;
}
} else if($fil !="." & $fil !="..") {
check_dir ($dir_root . $fil,$dir_root);
}
}
closedir($handle);
function check_dir( $off,$offt ) {
GLOBAL $file_list;
chdir("$off");
$handle = opendir("$off");
while (($file = readdir($handle))!==false) {
if(!is_dir($file)) {
if($file != "." & $file != "..") {
$file_list[] = $off . "/" . $file;
}
} else {
if($file != "." & $file != "..") {
check_dir ($off . "/" . $file,$off);
}
}
chdir("$offt");
}
closedir($handle);
}
This will give you an array, $file_list, that contains all files in all
directories from your root directory and on.
Does it help?
Jay
----- Original Message -----
From: "Tan JH" <jenhwi@visto.com>
To: <php-general@lists.php.net>
Sent: Thursday, December 07, 2000 9:08 AM
Subject: [PHP] Help on Opening dir by clicking (Urgent!!!)
Hi everybody,
I modified a code I got from one of u here last time when I asked a
question. The problem is the this modified code seems to work only for 2
level of dir but it does not work beyond that. Can anyone please explain how
I can use the code so that it is able to open any level of the dir? I
attached a file which contains the code.
Thanks in advance for helping me...
___________________________________________________________________________
Visit http://www.visto.com/info, your free web-based
communications center.
Visto.com. Life on the Dot.
----------------------------------------------------------------------------
----
> if ($view == "")
> {
>
> $handle=opendir("$basedir/$dir");
>
> print ("<table width=101%>\n");
>
> $count=0;
> if ($dir !="") $dir .= "/";
>
> while ($file = readdir($handle))
> {
> $count++;
>
> if (($file != ".") && ($file !=".."))
> {
>
> if (is_dir("$basedir/$file"))
> {
> print ("<tr><td width=5%><input type='checkbox'
> name='check.$count'
align='middle'></td>
> <td width=50%><a href=\"$PHP_SELF?dir=$file\">$file</a>
[DIR]</td>\n");
>
> $size=filesize($file);
> print("<td width=8%>$size</td>");
>
> $type=filetype($file);
> print("<td width=8%>$type</td>");
>
> $owner=fileowner($file);
> print("<td width=15%>$owner</td>");
>
> $date=filemtime($file);
> print("<td width=20%>$date</td></tr>");
>
> }
> else
> {
>
> print("<tr><td width=5%><input type='checkbox'
> name='check.$count'
align='middle'></td>
> <td width=50%><a href=\"$basedir/$dir$file\"
target='_blank'>$file</a></td>");
>
> $size=filesize($file);
> print("<td width=8%>$size</td>");
>
> $type=filetype($file);
> print("<td width=8%>$type</td>");
>
> $owner=fileowner($file);
> print("<td width=15%>$owner</td>");
>
> $date=filemtime($file);
> print("<td width=20%>$date</td></tr>");
>
> //if (ereg("php3$", $file)) {
> //print ("<td><a
> //href=\"$PHP_SELF?view=1&file=$dir$file\">View</a></td>");
> //}
>
> print ("</tr>\n");
> }
> }
> }
>
> print ("</table>");
>
> closedir($handle);
>
> }
> else
> {
>
> print ("<p>View: <b>$file</b><hr>\n");
>
> $fp = fopen("$basedir/$file", "r");
>
> //while (!feof($fp)) {
> //$line = fgets($fp, 4096);
>
> //$line = htmlentities($line);
> //$line = ereg_replace(" ", " ", $line);
> //printf ("%s<br>\n", $line);
> //}
>
> fpassthru($fp);
>
> fclose($fp);
>
> }
>
> -----------------------------7d029936b0378--
>
----------------------------------------------------------------------------
----
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net