PHP的WebExploer

<? 
############################################################ 
#This application is postcardware, meaning you can freely use any part
of it
#as long as you mail me the changes and write me a postcard from the c
ountry 
#your in. 

#I'm currently saving up to a new computer, and if you find this appli
cation usefull
#and would like to encourage me to write further programs, a small don
ation would be greatly 
#appreciated. $10 is recommended. 

#My adress is: 

#Sune Alexandersen 
#Kongsskogen 62 
#1370 Asker 
#Norway 

#IF YOU USE THIS PROGRAM, YOU REALLY DO NOT HAVE TO DO ANYTHING.. THE 
ABOVE THINGS ARE ONLY 
#SUGGESTIONS!! 
#BUT PLEASE EMAIL ME IF YOU FIND IT USEFULL OR IF YOU HAVE ANY SUGGEST
IONS!! 

#Newest version of this program can be found at www.suneworld.com/prog
rams 

#The bottom line is that this program is free to use for all. 
#You may modify this code as much you want, as long as you 
#mail me the updates, so I can impliment in my own app at will. 

#Live long and prosper my friend. 
#Kind regards, Sune Alexandersen, [email protected] 7.4.2000 
############################################################ 

############### Set up some variables and funcions 

############### CHANGE THIS TO YOUR DESIRED ROOT DIRECTORY 
$basedir "/path/to/your/dir"

############### Webexplorer version 
$version "RC 1.0"

############### Size for textarea 
$textrows "20"
$textcols "85"


############### If $wdir (working directory) isn't specified, set it a
s a slash (/) 
if(!
$wdir$wdir="/"

############### Variable for html ender 
$html_ender "</td></tr><tr><td colspan=\"2\"><hr></td></tr><tr><th c
olspan=\"2\" bgcolor=\"#4C4C99\"><font size=\"-1\" color=\"white\" fac
e=\"arial, helvetica\">Written by Sune Alexandersen 2000</th></
tr></table></body></html>"


############### Function for html header 
function html_header(){ 
global 
$basedir
global 
$wdir
global 
$lastaction
global 
$version 
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"
\"http://www.w3c.org/TR/REC-html40/loose.dtd\">"

echo 
"<HTML>"
echo 
"<HEAD>"
echo 
"<TITLE>WebExplorer $version</TITLE>"
echo 
"</HEAD>"
echo 
"<BODY bgcolor=\"#C0C0C0\" link=\"#4C4C99\" vlink=\"#4C4C99\" al
ink=\"#4C4C99\">"

echo 
"<table border=\"0\" align=\"center\" cellspacing=\"3\" cellpadd
ing=\"3\" width=\"600\">"

echo 
"<tr>"
echo 
" <th colspan=\"2\" width=\"100%\" bgcolor=\"#4C4C99\">"
echo 
"  <A HREF=\"$PHP_SELF?action=env&wdir=$wdir\"><img src=\"env.gi
f
\" alt=\"Environment\" border=\"0\">"
echo 
"  &nbsp;<font size=\"6\" color=\"white\" face=\"arial, helvetic
a
\">WebExplorer $version &nbsp"
echo 
"  <A HREF=\"$PHP_SELF?action=help&wdir=$wdir\"><img src=\"help.
gif
\" alt=\"Help\" border=\"0\">"
echo 
" </th>"
echo 
"</tr>"
echo 
"<tr>"
echo 
" <td width\"50%\" align=\"left\"><A HREF=\"$PHP_SELF?action=roo
t
\"><font size=\"4\" face=\"arial, helvetica\">Back to root
</td>"

echo 
" <td width\"50%\" align=\"right\"><A HREF=\"$PHP_SELF?wdir=$wdi
r
\" title=\"Refresh current dir\"><font size=\"4\" face=\"arial, helve
tica
\">$wdir<img src=\"explore.gif\" border=\"0\"></td>"
echo 
"</tr>"
echo 
"<tr>"
echo 
" <td colspan=\"2\"><hr></td>"
echo 
"</tr>"
echo 
"<tr>"
echo 
" <td colspan=\"2\"><font size=\"3\" color=\"#4C4C99\" face=\
"
arialhelvetica">$lastaction</td>"
echo 
"<tr>"
echo 
"<td colspan=\"2\"><hr><td>"
echo 
"</tr>"
echo 
"<tr>"
echo 
"<td colspan=\"2\">"


############ File size calculations 
function display_size($file){ 
$file_size filesize($file); 
if(
$file_size >= 1073741824
  { 
        
$file_size round($file_size 1073741824 100) / 100 "g";


elseif(
$file_size >= 1048576

        
$file_size round($file_size 1048576 100) / 100 "m"

elseif(
$file_size >= 1024

        
$file_size round($file_size 1024 100) / 100 "k"

else{ 
        
$file_size $file_size "b"

return 
$file_size


############ List the directory function 
function displaydir() 

global 
$basedir
global 
$wdir

############### Draw the head table 
echo "<TABLE BORDER=\"0\" cellspacing=\"1\" cellpadding=\"1\" width=\
"
100%">"
echo 
"<tr>"
echo 
"<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, hel
vetica\">Type</th>"

echo 
"<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, hel
vetica\">Name</th>"

echo 
"<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, hel
vetica\">Size</th>"

echo 
"<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, hel
vetica\">Modified</th>"

echo 
"<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, hel
vetica\">Perm's</th>"

echo 
"<th bgcolor=\"#4C4C99\"><font color=\"white\" face=\"arial, hel
vetica\">Action</th>"

echo 
"</tr>"

################## Load Directory and Files into seperate arrays 
chdir($basedir $wdir); 
$handle=opendir("."); 
while (
$file readdir($handle)) 

if(
is_dir($file)) $dirlist[] = $file
if(
is_file($file)) $filelist[] = $file

closedir($handle); 

############### Put the directories first 
if($dirlist

############### Sort alphabetically 
asort($dirlist); 
############### Walk through array 
while (list ($key$file) = each ($dirlist)) 

################## Skip the tiresome "." 
if (!($file == ".")) 

$filename=$basedir.$wdir.$file
$fileurl=rawurlencode($wdir.$file); 
$lastchanged filectime($filename); 
$changeddate date("d-m-Y H:i:s"$lastchanged); 
echo 
"<TR>"

############### Put up the PARENT arrow 
if($file == ".."

$downdir dirname("$wdir"); 
echo 
"<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chd
r&file=$downdir
\"><img src=\"parent.gif\" alt=\"Parent directory\" bor
der=
\"0\"></TD>\n"
echo 
"<TD></TD>\n"
echo 
"<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial
, helvetica\">" 
display_size($filename) . "</TD>"
echo 
"<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial
, helvetica\">" 
$changeddate "</TD><TD align=\"right\">"
printf("%o", (fileperms($filename)) & 0777); 
echo 
"</TD><TD nobreak>"
echo 
"<A HREF=\"$PHP_SELF?action=chdr&file=$downdir\"><img src=\"
parent.gif
\" alt=\"Parent directory\" border=\"0\"> "


############### List the directory 
else 

$lastchanged filectime($filename); 
echo 
"<TD align=\"center\" nobreak><A HREF=\"$PHP_SELF?action=chd
r&file=$fileurl
\"><img src=\"folder.gif\" alt=\"Change working directo
ry to $file
\" border=\"0\"></TD>\n"
echo 
"<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" 
htmlspecialchars($file) . "</TD>\n"
echo 
"<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial
, helvetica\">" 
display_size($filename) . "</TD>"
echo 
"<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial
, helvetica\">" 
$changeddate "</TD><TD align=\"right\">"
echo 
"<A HREF=\"$PHP_SELF?action=chmod&file=$filename\"><font siz
e =
\"-1\" face=\"arial, helvetica\">"
printf("%o", (fileperms($filename)) & 0777); 
echo 
""
echo 
"</TD><TD nobreak>"
echo 
" <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"
><img src=
\"move.gif\" alt=\"Move,rename or copy $file\" border=\"0\">
 "

echo 
" <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fil
eurl
\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\"> ";

echo 
"<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><
img src=
\"delete.gif\" alt=\"Delete $file\" border=\"0\"> "





############### List the files 
if($filelist

############### Sort the filelist alphabetically 
asort($filelist); 
while (list (
$key$file) = each ($filelist)) 


############### Check what fileformat it is and give it the correct
 
icon and attributes 

############### Image 
if (ereg(".gif|.jpg",$file)) 

$icon "<IMG SRC=\"image.gif\" alt=\"Image\" border=\"0\">"
$browse "1"
$raw "0"
$image "1"


############### Textfile 
elseif (ereg(".txt",$file)) 

$icon "<IMG SRC=\"text.gif\" alt=\"Text\" border=\"0\">"
$browse "1"
$raw "1"
$image "0"


############### Audiofile 
elseif (ereg(".wav|.mp2|.mp3|.mp4|.vqf|.midi",$file)) 

$icon "<IMG SRC=\"audio.gif\" alt=\"Audio\" border=\"0\">"
$browse "1"
$raw "0"
$image "0"


############### Webscript 
elseif (ereg(".phps|.php|.php2|.php3|.php4|.asp|.asa|.cgi|.pl|.shtm
l"
,$file))  

$icon "<IMG SRC=\"webscript.gif\" alt=\"Web program\" border=\"0
\">"

$browse "1"
$raw "1"
$image "0"


############### Apache Webserver security settings 
elseif (ereg(".htaccess",$file)) 

$icon "<IMG SRC=\"security.gif\" alt=\"Apache Webserver security
settings\" border=\"0\">" 

$browse "0"
$raw "1"
$image "0"


############### Web page 
elseif (ereg(".html|.htm",$file)) 

$icon "<IMG SRC=\"webpage.gif\" alt=\"Web page\" border=\"0\">";

$browse "1"
$raw "1"
$image "0"


############### Unknown 
else 
{  
$icon "<IMG SRC=\"text.gif\" alt=\"Unknown filetype\" border=\"0
\">"

$browse "1"
$raw "1"
$image "0"


############### List the files 
$filename=$basedir.$wdir.$file
$fileurl=rawurlencode($wdir.$file); 
$lastchanged filectime($filename); 
$changeddate date("d-m-Y H:i:s"$lastchanged); 
echo 
"<TR>"
echo 
"<TD align=\"center\" nobreak>"

############### Make the fileicon clickable for quickviewing 
if($raw == "1"

echo 
"<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl\">"


if(
$image == "1"

echo 
"<A HREF=\"$PHP_SELF?action=show&wdir=$wdir&file=$fileurl&ima
ge=$image
\">"

echo 
"$icon</TD>\n"
echo 
"<TD nobreak><font size =\"-1\" face=\"arial, helvetica\">" 
htmlspecialchars($file) . "</TD>\n"
echo 
"<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, 
helvetica\">" 
display_size($filename) . "</TD>"
echo 
"<TD align=\"right\" nobreak><font size =\"-1\" face=\"arial, 
helvetica\">" 
$changeddate "</TD><TD align=\"right\">"
echo 
"<A HREF=\"$PHP_SELF?action=chmod&wdir=$wdir&file=$fileurl\" t
itle=
\"Change permission level on $file\"><font size =\"-1\" face=\"ar
ial, helvetica
\">"
printf("%o", (fileperms($filename)) & 0777); 
echo 
""
echo 
"</TD><TD nobreak>"
echo 
" <A HREF=\"$PHP_SELF?action=move&wdir=$wdir&file=$fileurl\"><
img src=
\"move.gif\" alt=\"Move,rename or copy $file\" border=\"0\"></
A> "

echo 
" <A HREF=\"$PHP_SELF?action=touch&wdir=$wdir&touchfile=$fileu
rl
\"><img src=\"touch.gif\" alt=\"Touch $file\" border=\"0\"> "
echo 
"<A HREF=\"$PHP_SELF?action=del&wdir=$wdir&file=$fileurl\"><im
g src=
\"delete.gif\" alt=\"Delete $file\" border=\"0\"> "

############### If the file can be browsed, give it the browse icon

if($browse == "1"

echo 
" <A HREF=\"$wdir$file\"><img src=\"browse.gif\" alt=\"Browse
\" border=\"0\"> "


############### If the file can be edited, give it the edit icon 
if($raw =="1"

echo 
" <A HREF=\"$PHP_SELF?wdir=$wdir&action=edit&file=$fileurl\">
<img src=
\"edit.gif\" alt=\"Edit\" border=\"0\"> "



echo 
"</TD></TR>\n"
echo 
"</TABLE>"

############### Display forms for different actions 
echo "<table border=\"0\" width=\"100%\">"
echo 
"<TR><TD colspan=\"2\"><hr></td>"

############### Upload file 
echo "<TR><TD><font size =\"-1\" face=\"arial, helvetica\">Upload fil
e</td><td>"

echo 
"<FORM ENCTYPE=\"multipart/form-data\" METHOD=\"POST\" ACTION=\"
$PHP_SELF
\">"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">"
echo 
"<INPUT NAME=\"userfile\" TYPE=\"file\" size=\"40\">"
echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"upload\" VALUE=\"Go!\"></TD></TR>
"

echo 
"</FORM>"

############### Create directory 
echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">"
echo 
"<TR><TD><font size =\"-1\" face=\"arial, helvetica\">Create dir
ectory</td><td>"

echo 
"<INPUT TYPE=\"TEXT\" NAME=\"mkdirfile\" size=\"40\">"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"mkdir\">"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">"
echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"mkdir\" VALUE=\"Go!\"></TD></TR>
"

echo 
"</FORM>"

############### Create file 
echo "<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">"
echo 
"<TR><TD><font size =\"-1\" face=\"arial, helvetica\">Create Fil
e</td><td>"

echo 
"<INPUT TYPE=\"TEXT\" NAME=\"file\" size=\"40\">"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\"> ";

echo 
"<input type=\"checkbox\" name=\"html\" value=\"yes\"><font size
=\"-2\" face=\"arial, helvetica\">(html template) "

echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">"
echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"createfile\" VALUE=\"Go!\">"
echo 
"</TD></TR>"
echo 
"</TABLE>"
echo 
"</FORM>"


######################################################################
################################### 

############### The user pressed CANCEL, set the $action to nothing 
if($cancel$action=""

############### Upload file 
if($upload)  

copy($userfile,$basedir.$wdir.$userfile_name);  
$lastaction "Uploaded $userfile_name to $wdir"
html_header(); 
displaydir(); 
echo 
$html_ender
exit; 


######################################################################
################################### 
############### Begin actions code 
switch ($action


######################################################################
################################### 
############### No $action variable? Display initial page 
case ""
$lastaction "Listing directory"
html_header(); 
displaydir(); 
echo 
$html_ender
break; 


######################################################################
################################### 
############### Help 
case "help"
$lastaction "Displaying help"
html_header(); 
?> 
<font face=\"arial, helvetica\"> 


<h3> 
<a href="#introduction">1. Introduction<br> 
<a href="#installing">2. Installing<br> 
<a href="#requirements">3. Requirements<br> 
<a href="#filetypes">4. Description of filetypes<br> 
<a href="#actions">5. Description of actions<br> 
<a href="#bugreport">6. Bug report<br> 
<a href="#thanksto">7. Thanks to<br> 
<a href="#about">8. About the author<br> 
</h3> 


<hr> 

<h3><a name="introduction">1. Introduction</h3> 
I was looking for a good browser-based file manager when  
I thought that I could write my own. 
Since I have never been a programming wiz', I had 
to learn by doing. I'm actually quite satisfied with how 
WebExplorer turned out, and I'd love to hear of anybody  
using it. Drop me a line at <a href="mailt:[email protected]">
[email protected].<br> 
You can always find the newes version of this file at WebExplorers <
a href="www.suneworld.com/apps">website.<br> 
<a href="#top">[Top]<p> 

<h3><a name="installing">2. Installing</h3> 
Just put all the files into your desired directory 
(example www.yourdomain.com/webexplorer) and edit the 
following line in the scipt:<br> 
$basedir="/path/to/your/dir";<br> 
to your desired root directory. 
<P> 
IT IS HIGLY RECOMMENDED THAT YOU PASSWORD SECURE THIS DIRECTOR
Y!<br> 
<a href="#top">[Top]<p> 

<h3><a name="requirements">3. Requirements</h3> 
A webserver with PHP3 or newer installed. The HTML outputed is ment 
to be all-browser combatible.<br> 
<a href="#top">[Top]<p> 

<h3><a name="filetypes">4. Description of filetypes</h3> 
(Most of the icons are clickable.) 


<table border="0"> 
<tr> 
<td valign="top"><img src="folder.gif"></td> 
<td>Indicates that the object is a folder.<br> 
Click to change to this directory</td> 
</tr> 
<tr> 
<td valign="top"><img src="security.gif"></td> 
<td>File is a Apache Webserver security file (.httaccess).<br> 
Click to view source</td> 
</tr> 
<tr> 
<td valign="top"><img src="audio.gif"></td> 
<td>File is an audiofile</td> 
</tr> 
<tr> 
<td valign="top"><img src="webpage.gif"></td> 
<td>File is either an HTML or HTM file. Wievable directoly in you b
rowser.<br> 
Click to view source</td> 
</tr> 
<tr> 
<td valign="top"><img src="webscript.gif"></td> 
<td>File is either an PHP, PHPS, PHP2, PHP3, PHP4, ASP, ASA, CGI, 
PL or SHTML file. The file needs to be processed server-side before

viewable in browser. For example; WebExplorer is an PHP3 file.<br> 

Click to view source</td> 
</tr> 
<tr> 
<td valign="top"><img src="image.gif"></td><td>File is either a GIF
 of a JPG file. Viewable 
image in any browser.<br> 
Click to view.</td> 
</tr> 
</table> 


<a href="#top">[Top]<p> 

<h3><a name="actions">5. Description of actions</h3> 


<table border="0"> 
<tr> 
<td valign="top"><img src="explore.gif"></td> 
<td>Refresh current directory.</td> 
</tr> 
<tr> 
<td valign="top"><img src="parent.gif"></td> 
<td>Go to parent directory.</td> 
</tr> 
<tr> 
<td valign="top"><img src="delete.gif"></td> 
<td>Delete the file or directory. You will be prompted for confirma
tion.</td> 
</tr> 
<tr> 
<td valign="top"><img src="browse.gif"></td> 
<td>Browse the file in browser.</td> 
</tr> 
<tr> 
<td valign="top"><img src="edit.gif"></td> 
<td>Edit the file in plain text.</td> 
</tr> 
<tr> 
<td valign="top"><img src="move.gif"></td> 
<td>Will move the file or directory to a location you specify.</td>

</tr> 
<tr> 
<td valign="top"><img src="touch.gif"></td> 
<td>Will create a new timestamp on the object.</td> 
</tr> 
</table> 


<a href="#top">[Top]<p> 

<h3><a name="bugreport">5. Bug report</h3> 
I found no bugs at release. If you discover any, or have any suggest
ions, PLEASE report 
them to me at president@sun
eworld.com 
or by using <a href="<? echo "$PHP_SELF?action=bugreport&wdir=$wdir"
?>">this form.<br> 
<a href="#top">[Top]<p> 

<h3><a name="thanksto">6. Thanks to</h3> 
I'd like to thank all the regulars at #php @ Efnet, 
Stian Gryt鴜r and J鴕n Morten Innselset. I wouldn't have made this 
without their invaluable help.<br> 
<a href="#top">[Top]<p> 

<h3><a name="about">7. About the author</h3> 
Sune Alexandersen was born in 1976 in Norway. Sune has his personal 
website at  
www.suneworld.com. 
He often use PHP, but this is his first program written entirely in 
PHP. 
Although this program is freeware, he would appreciate a postcard fr
om your part 
of the world or a small money donation (saving up to by his private 
computer!) if you use it. 
<br>His adress is 

<p> 
Sune Alexandersen<br> 
Kongsskogen 62<br> 
1385 Asker<br> 
Norway<br> 

<p> 
He can be reached at presid
[email protected]
<br><a href="#top">[Top]<p> 
<? 
echo $html_ender
break; 

######################################################################
################################### 
############### User pressed ROOT.. Change to root dir 
case "root"
$wdir="/"
$lastaction "Changed to root directory"
html_header(); 
displaydir(); 
echo 
$html_ender
break; 

######################################################################
################################### 
############### Display PHP env 
case "env"
$lastaction "Displaying PHP environment"
html_header(); 
phpinfo(); 
echo 
$html_ender
break; 

######################################################################
################################### 
############### Change directory 
case "chdr"
$wdir=$file."/"
$lastaction "Changed directory to $wdir"
html_header(); 
displaydir(); 
echo 
$html_ender
break; 

######################################################################
################################### 
############### Touch object (create a new timestamp) 
case "touch"
touch($basedir.$touchfile); 
$lastaction "Touched $touchfile"
html_header(); 
displaydir(); 
echo 
$html_ender
break; 

######################################################################
################################### 
############### Bug report form 
case "bugreport"
if (
$send

$lastaction "Bug reported. Thank you!"
html_header(); 
mail("[email protected]","Bug report","Name: $name \nVersion:
$version 
\n\nProblem: $problem"); 
echo 
"<h3><a href=\"$PHP_SELF?action=help&wdir=$wdir\">Back to help
</h3>"


else 

$lastaction "Bug report form"
html_header(); 
?> 
<table> 
<form action="<? echo "$PHP_SELF?action=bugreport&wdir=$wdir&send=1
"
?>" method="POST"> 
<tr> 
<td>Your name:</td> 
<td><input name="name" size="24" maxlength="30"></td> 
</tr><tr> 
<td>Your email adress:</td> 
<td><input name="email" size="24" maxlength="30"></td> 
</tr><tr> 
<td>Description of problem(s):</td> 
<td><textarea name="problem" cols="30" rows="5"></textarea></td> 
</tr><tr> 
<td colspan="2" align="center"><input type="submit" value="Send"><
/td> 
</tr> 
</table> 
<? 

echo 
$html_ender
break; 

######################################################################
################################### 
############### Delete file or directory 
case "del"

############### The user has comfirmed the deletion 
if ($confirm


############### Object is a directory 
if(is_dir($basedir.$file)) 

rmdir($basedir.$file); 


############### Object is a file 
else 

unlink($basedir.$file); 

$lastaction "Deleted $file"
html_header(); 
displaydir(); 


############### Prompt the user for confirmation 
else 

$lastaction "Are you sure you want to DELETE<br>$file?"
html_header(); 
echo 
"<center><font size =\"5\" face=\"arial, helvetica\"><A HRE
F=
\"$PHP_SELF?action=del&wdir=$wdir&file=$file&confirm=1\">YES!</f
ont><br>"

echo 
"<p><font size =\"5\" face=\"arial, helvetica\"><A HREF=\"$PHP
_SELF?wdir=$wdir
\">NO!<br></center>"

echo 
$html_ender
break; 

######################################################################
################################### 
############### Change permission level 
case "chmod"

############### The user has confirmed 
if ($confirm

$level "0"
$level .= $owner
$level .= $group
$level .= $public
$showlevel $level
$level=octdec($level); 
chmod($basedir.$file,$level); 
$lastaction "Changed permission on $file to $showlevel"
html_header(); 
displaydir(); 


############### Prompt the user for confirmation 
else 

$lastaction "Change permission level on $file"
html_header(); 
echo 
"<font face=\"arial, helvetica\"><center><h4>Current level: ";

printf("%o", (fileperms($basedir.$file)) & 0777); 
echo 
"</h4><FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n"

function 
selections() 

echo 
"<option value=\"0\">0 - No permissions"
echo 
"<option value=\"1\">1 - Execute"
echo 
"<option value=\"2\">2 - Write "
echo 
"<option value=\"3\">3 - Execute & Write"
echo 
"<option value=\"4\">4 - Read"
echo 
"<option value=\"5\">5 - Execute & Read"
echo 
"<option value=\"6\">6 - Write & Read"
echo 
"<option value=\"7\">7 - Write, Execute & Read"
echo 
"</select>"


echo 
"<p><h4>Owner<br>"
echo 
"<select name=\"owner\">"
selections(); 

echo 
"<p>Group<br>"
echo 
"<select name=\"group\">"
selections(); 

echo 
"<p>Public<br>"
echo 
"<select name=\"public\">"
selections(); 

echo 
"</h4>"
echo 
"<p>"
echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Change\">\n";

echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\">\n"

echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"chmod\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">"
echo 
"</FORM>"
echo 
"</center>"

echo 
$html_ender
break; 

######################################################################
################################### 
############### Move file 
case "move"
############### The user has confirmed renaming/moving/copying of th
e object 
if($confirm && $newfile
  { 
############### The destination object exists 
     
if(file_exists($basedir.$newfile)) 

$lastaction "Destination file already exists. Aborted."

else 

if(
$do == copy

copy($basedir.$file,$basedir.$newfile); 
$lastaction "Copied\n$file to $newfile"

else 

rename($basedir.$file,$basedir.$newfile); 
$lastaction "Moved/renamed\n$file to $newfile"


html_header(); 
displaydir(); 
     echo 
$html_ender


############### Prompt the user for destinanotion name and action 
else 

$lastaction "Moving/renaming or copying<br>$file"
html_header(); 
echo 
"<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n"
echo 
"<select name=\"do\">"
echo 
"<option value=\"copy\">Copy"
echo 
"<option value=\"move\">Move/rename"
echo 
"</select> "
echo 
"($file)"
echo 
"<h4>To</h4>"
echo 
"<INPUT TYPE=\"TEXT\" NAME=\"newfile\" value=\"$file\" size=\"
40
\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n"

echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"move\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n"
echo 
"<p>"
echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Do\">\n"
echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\">\n"

echo 
"</FORM>"
echo 
$html_ender

break; 

######################################################################
################################### 
############### Edit file 
case "edit"

############### The user is done editing. Return to main screen 
if($confirm && $file
    { 
     
$lastaction "Edited $file"
html_header(); 
$fp=fopen($basedir.$file,"w"); 
     
fputs($fp,stripslashes($code)); 
     
fclose($fp); 
displaydir(); 


############### Display file in textarea 
else 

$lastaction "Editing $file"
html_header(); 
echo 
"<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"edit\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n"
$fp=fopen($basedir.$file,"r"); 
$contents=fread($fp,filesize($basedir.$file)); 
echo 
"<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\"
>
\n"
echo 
htmlspecialchars($contents); 
echo 
"</TEXTAREA><BR>\n"
echo 
"<center><INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Save\
"
>n"; 
echo "
<INPUT TYPE="SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\"></cen
ter><BR>\n"

echo 
"</FORM>"

echo 
$html_ender
break; 


######################################################################
################################### 
############### Display file 
case "show"

############### Display file in textformat 
$filelocation $wdir.$file
$lastaction "Displaying $file"
html_header(); 

############### It is a picture, display it. 
if($image == "1"

echo 
"<center><img src=\"$file\"></center>"


############### It is text, display it. 
else 

show_source($basedir.$file); 

echo 
$html_ender
break; 

######################################################################
################################### 
############### Create directory 
case "mkdir"

############### The directory already exists.  
if(file_exists($basedir.$wdir.$mkdirfile)) 

$lastaction "The directory $wdir$mkdirfile allready exists."
html_header(); 


############### Create directory 
else 

$lastaction "Created the directory $wdir$mkdirfile"
html_header(); 
mkdir($basedir.$wdir.$mkdirfile,0750); 

displaydir(); 
echo 
$html_ender
break; 

######################################################################
################################### 
############### Create file 
case "createfile"
$filelocation $wdir.$file

############### The user is done editing. Return to main screen 
if($done == "1"
    { 
$lastaction "Created $file"
html_header(); 
$fp=fopen($basedir.$filelocation,"w"); 
fputs($fp,stripslashes($code)); 
fclose($fp); 
displaydir(); 


############### Display a textarea that will be the file 
else 


    
############### The file already exists 
    
if(file_exists($basedir.$filelocation)) 
    { 
    
$lastaction "$file already exists."
html_header(); 
displaydir(); 


############### Give the user a textarea to write the contents of f
ile 
else 

$lastaction "Creating $file"
html_header(); 
echo 
"<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"file\" VALUE=\"$file\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"action\" VALUE=\"createfile\">
\n"

echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"wdir\" VALUE=\"$wdir\">\n"
echo 
"<INPUT TYPE=\"HIDDEN\" NAME=\"done\" VALUE=\"1\">\n"
echo 
"<TEXTAREA NAME=\"code\" rows=\"$textrows\" cols=\"$textcols\
"
>n"; 

############### The user selected to use a html template. Put it i
nside of the textarea 
if(isset($html)) 
{ 
echo "
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//
EN\">\n\n"

echo 
"<html>\n"
echo 
"<head>\n\n"
echo 
" <title>Untitled</title>\n"
echo 
"</head>\n"
echo 
"<body>\n\n\n\n"
echo 
"</body>\n"
echo 
"</html>"

echo 
"</TEXTAREA><BR>\n"
echo 
"<center><INPUT TYPE=\"SUBMIT\" NAME=\"confirm\" VALUE=\"Crea
te\">\n"

echo 
"<INPUT TYPE=\"SUBMIT\" NAME=\"cancel\" VALUE=\"Cancel\"></ce
nter><BR>\n"

echo 
"</FORM>"


echo 
$html_ender
break; 

?>