note 65426 added to function.opendir
| From: | cynthia at heathernova dot info | Date: | Sun, 30 Apr 2006 16:36:54 +0000 |
| Subject: | note 65426 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-110195@lists.php.net to get a copy of this message | ||
Hi tozeiler, I have adjusted your code a little bit and changed it into a 'filemanager'.
It will open the specified file or directory on your webserver.
<?php
# This is a simple filemanager for your webserver
#
# Feel free to use it ;-)
$new_url = $_GET[new_url];
// this is the path where the script start,
// change it into your own.
$path="../downloads/";
$dh = opendir($path);
echo ("<table border=0><tr>\n");
// This is the first_time that the program is used
if ($new_url == ""):
while (($file = readdir($dh)) !== false) {
$file = trim($file);
$test=strlen($file);
$total = $path . $file;
$bytes = filesize($total);
$type=filetype($file);
if ( $type == "dir" & $file != "..") :
?><td><a href="testbank-2.php?new_url=<?php echo $path. "" . $file;
?>/" target="_self"><?php echo $file;?></a>
open this directory</td></tr>
<?php
endif;
if ( $type != "dir" ) :
?>
<td width="265"><a title="<?php echo $file; ?> <?php echo $type;
?>" href="<?php echo $path . "" . $file; ?>"
target="_blank"><?php echo $file; ?></a> <?php echo $bytes; ?>
bytes</td></tr>
<?php
endif;
}
closedir($dh);
echo ("</table>");
endif;
// User want to look in a sub directory..
if ($new_url !=""):
$path=$new_url;
$dh = opendir($path);
echo ("<table border=0><tr>\n");
while (($file = readdir($dh)) !== false) {
$file = trim($file);
$test=strlen($file);
$total = $path . $file;
$bytes = filesize($total);
$type=filetype($file);
if ( $type == "dir") :
?><td width="265"><a href="testbank-2.php?new_url=<?php echo $path.
"" . $file; ?>/" target="_self"><?php echo $file;?></a>
open this directory</td></tr>
<?php
endif;
if ( $type != "dir" ) :
?>
<td width="265"><a title="<?php echo $file; ?> <?php echo $type;
?>" href="<?php echo $path . "" . $file; ?>"
target="_blank"><?php echo $file; ?></a> <?php echo $bytes; ?>
bytes</td></tr>
<?php
endif;
}
closedir($dh);
echo ("</table>");
endif;
?>
----
Server IP: 194.109.193.119
Probable Submitter: 85.144.152.210
----
X-Spam-Status: No, hits=4.8 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_40_50,HTML_MESSAGE,HTML_TAG_BALANCE_TABLE autolearn=no
version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- http://master.php.net/note/edit/65426
Del: integrated -- http://master.php.net/note/delete/65426/integrated
Del: useless -- http://master.php.net/note/delete/65426/useless
Del: bad code -- http://master.php.net/note/delete/65426/bad+code
Del: spam -- http://master.php.net/note/delete/65426/spam
Del: non-english -- http://master.php.net/note/delete/65426/non-english
Del: in docs -- http://master.php.net/note/delete/65426/in+docs
Del: other reasons-- http://master.php.net/note/delete/65426
Reject -- http://master.php.net/note/reject/65426
Search -- http://master.php.net/manage/user-notes.php