home *** CD-ROM | disk | FTP | other *** search
- filemanager
-
- Provides a simple web-based file manager and text editor. No security included.
-
- <?php
-
- # filemanager by Lacey Pevey
- # v0.02 - 1999/12/05 13:46 CST
- #
- # You are free to use and distribute this code provided this tiny
- # header is included. No warranties, fitness for purpose, etc. etc.
- #
- # Please send comments/bugfixes/enhancements to
- # lpevey@mailhost.tcs.tulane.edu.
-
- $home = "/home"; //include user's home directory (or whatever you want to give them access to)
-
- include("header.inc");
-
- ?>
-
- <script language=javascript>
- <!--
- function submit(form) {
- form.submit()
- }
- //-->
- </script>
-
- <?php
-
- if (isset($exit)) { unset($edit); unset($upload); }
-
- if (empty($pwd)) $pwd = "/";
-
- if ($action == "upload") exec("cp $userfile $home$pwd$userfile_name");
-
- $file = $home.$pwd.$fn;
-
- function read_file($file) {
-
- if (!($fp = fopen($file, 'r' ))) return false;
-
- $contents = fread($fp, filesize($file));
-
- fclose($fp);
-
- return $contents;
- }
-
- function write_file($file, $contents) {
-
- if ($fp = fopen($file, "w")) {
-
- fputs($fp, $contents, strlen($contents));
-
- fclose($fp);
-
- return 1;
-
- } else {
-
- return 0;
- }
- }
-
- //-------------------------------------------------------------------------------------------------
-
- if ($copy) {
-
- if ($action == "copy") {
-
- exec("cp -R ".$home.$oldname." ".$home.$newname);
-
- } else {
-
- ?>
- <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
- <tr>
- <form name=copy method=post action=<?php echo $PHP_SELF; ?>>
- <td>
- <input type=hidden name=oldname value="<?php echo $pwd.$fn; ?>">
- <input type=hidden name=action value=copy>
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <font face=Verdana><small>Clipboard Contents: <?php echo $pwd.$fn; ?></small></font><br>
- <input type=submit name="copy" value="Copy as:">
- <input type=text size="56" name="newname" value="<?php echo $pwd.$fn; ?>"><br>
- <input type=submit name="exit" value="Cancel"></td>
- </form>
- </tr>
- </table><br><br>
- <?php
-
- }
- }
-
- //-------------------------------------------------------------------------------------------------
-
- if ($move) {
-
- if ($action == "move") {
-
- exec("mv ".$home.$oldname." ".$home.$newname);
-
- } else {
-
- ?>
- <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
- <tr>
- <td>
- <form name=move method=post action=<?php echo $PHP_SELF; ?>>
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <font face=Verdana><small>Clipboard Contents: <?php echo $pwd.$fn; ?></small></font><br>
- <input type=submit name="move" value="Move to:">
- <input type=text size="56" name="newname" value="<?php echo $pwd.$fn; ?>"><br>
- <input type=hidden name=oldname value="<?php echo $pwd.$fn; ?>">
- <input type=hidden name=action value=move>
- <input type=submit name="exit" value="Cancel"></td></form>
- </tr>
- </table><br><br>
- <?php
-
- }
- }
-
- //-------------------------------------------------------------------------------------------------
-
- if ($rename) {
-
- if ($action == "rename") {
-
- exec("mv ".$home.$oldname." ".$home.$newname);
-
- } else {
-
- ?>
- <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
- <tr>
- <td>
- <form name=move method=post action=<?php echo $PHP_SELF; ?>>
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <font face=Verdana><small>Clipboard Contents: <?php echo $pwd.$fn; ?></small></font><br>
- <input type=submit name="rename" value="Rename to:">
- <input type=text size="56" name="newname" value="<?php echo $pwd.$fn; ?>"><br>
- <input type=hidden name=oldname value="<?php echo $pwd.$fn; ?>">
- <input type=hidden name=action value=rename>
- <input type=submit name="exit" value="Cancel"></td></form>
- </tr>
- </table><br><br>
- <?php
-
- }
- }
-
- //-------------------------------------------------------------------------------------------------
-
- if ($newfile) {
-
- if (isset($fn)) {
-
- write_file($file, "");
-
- $edit = 1;
-
- } else {
-
- echo "You must specify a name for the file you wish to create.";
- }
-
- echo $result;
-
- }
-
- //-------------------------------------------------------------------------------------------------
-
- if ($newdir) {
-
- if (isset($newdirname)) {
-
- exec("mkdir ".$home.$pwd.$newdirname);
-
- } else {
-
- echo "You must specify a name for the directory you wish to create.";
- }
-
- echo $result;
- }
-
- //-------------------------------------------------------------------------------------------------
-
- if ($delete) {
-
- if ($action == "delete") {
-
- exec("rm -R $file");
-
- } else {
-
- ?>
- <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
- <tr>
- <td>
- <form name=delete method=post action=<?php echo $PHP_SELF; ?>>
- <font face=Verdana><small>Delete <?php echo $pwd.$fn; ?>?</small></font>
- <input type=submit name="delete" value="Yes">
- <input type=submit name="exit" value="No">
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <input type=hidden name="fn" value="<?php echo $fn; ?>">
- <input type=hidden name=action value=delete></td></form>
- </tr>
- </table><br><br>
- <?php
-
- }
- }
-
- //-------------------------------------------------------------------------------------------------
-
- if (isset($edit)) {
-
- if (!(isset($fn))) echo "No filename was specified.";
-
- else {
-
- if ($save) {
-
- if ((isset($file)) && (isset($contents))) {
-
- $contents = stripslashes($contents);
-
- write_file($file, $contents);
-
- } else {
-
- echo "Error saving file to disk";
- }
- }
- ?>
- <table bgcolor="#999999" border=2 cellspacing=0 cellpadding=3 align=center>
- <tr>
- <td>Current File: <?php echo $fn; ?></td>
- </tr
- <tr>
- <td align=center>
- <form method="post" action="<?php echo $PHP_SELF; ?>">
- <textarea name="contents" cols=100 rows=25><?php $contents = read_file($home.$pwd.$fn); echo htmlentities($contents); ?></textarea><br>
- <input type=submit name="save" value="Save">
- <input type=submit name="exit" value="Exit">
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <input type=hidden name="fn" value="<?php echo $fn; ?>">
- <input type=hidden name="edit" value="Edit"></td></form>
- </tr>
- </table></form><br>
- <?php
-
- }
- }
-
- //-------------------------------------------------------------------------------------------------
-
- exec("ls -l ".$home.$pwd, $result, $id);
-
- $up_pwd = eregi_replace("/$", "", $pwd);
-
- $up_pwd = eregi_replace("[_a-z0-9\.-]+$", "", $up_pwd);
-
- echo "
- <table align=center bgcolor=#999999 border=2 cellspacing=0 cellpadding=3>
- <tr>
- <td>Current Directory: ".$pwd."</td>
- </tr>
- <tr>
- <td>
- <table>
- <tr>
- <td colspan=2><font face=Verdana><small>Folders:</small></font><td>
- </tr>
- <tr>
- <td><form name=up action=$PHP_SELF method=post><input type=hidden name=pwd value=$up_pwd><a href=\"javascript:submit(document.forms['up']);\"><img src=/img/up.gif border=0 alt=up></a> </form></td>
- <td><form method=post action=$PHP_SELF name=folders>
- <select name=pwd>";
-
- $i = 1;
-
- while (isset($result[$i])) {
-
- $result[$i] = eregi_replace(" +", ",", $result[$i]);
-
- $line = explode(",", $result[$i]);
-
- if (ereg("^d", $line[0])) {
-
- echo "<option value=\"".$pwd.$line[8]."/\">".$line[8]."\n";
- }
-
- $i++;
- }
- ?>
- </select>
- <input type=submit value="Open">
- <input type=submit name="move" value="Move">
- <input type=submit name="copy" value="Copy">
- <input type=submit name="delete" value="Delete">
- <input type=submit name="rename" value="Rename">
- </form></td>
- </tr>
- </table></td>
- </tr>
- <tr>
- <td>
- <form method=post action="<?php echo $PHP_SELF; ?>" name="files">
- <font face=Verdana><small>Files:</small></font><br>
- <select name=fn>
- <?php
-
- $i = 1;
-
- while (isset($result[$i])) {
-
- $result[$i] = eregi_replace(" +", ",", $result[$i]);
-
- $line = explode(",", $result[$i]);
-
- if (!(ereg("^d", $line[0]))) {
-
- echo "<option value=\"".$line[8]."\">".$line[8]."\n";
- }
-
- $i++;
- }
- ?>
- </select>
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <input type=submit name="edit" value="Edit">
- <input type=submit name="move" value="Move">
- <input type=submit name="copy" value="Copy">
- <input type=submit name="delete" value="Delete">
- <input type=submit name="rename" value="Rename">
- </form></td>
- </tr>
- <tr>
- <td>
- <table width=100%>
- <tr>
- <td width=50% nowrap>
- <form method=post action="<?php echo $PHP_SELF; ?>" name="newfile">
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <font face=Verdana><small>New File:</small></font><br>
- <input type=text name=fn size=20 maxlength=100>
- <input type=submit name=newfile value="Create">
- </form></td>
- <td width=50% nowrap>
- <form method=post action="<?php echo $PHP_SELF; ?>" name="newfolder">
- <input type=hidden name="pwd" value="<?php echo $pwd; ?>">
- <font face=Verdana><small>New Folder:</small></font><br>
- <input type=text name=newdirname size=20 maxlength=100>
- <input type=submit name=newdir value="Create">
- </form></td>
- </tr>
- </table></td>
- </tr>
- <tr>
- <td>
- <form method=post enctype="multipart/form-data" action=<?php echo $PHP_SELF; ?>>
- <font face=Verdana><small>File Upload:</small></font><br>
- <input type=hidden name="pwd" value=<?php echo $pwd; ?>>
- <input type=hidden name="action" value=upload>
- <input type=file name=userfile size=40>
- <input name=upload value=" Upload " type=submit>
- </form></td>
- </tr>
- </table>
- <br>
- <br>
-
- <?php
-
- include("footer.inc");
-
- ?>
-