Copy Code code as follows:
<?php
/*
Traverse folder; Functions: (a) can delete the file (b) editable text, Web page file (c) can be deleted folder, if the folder is empty (d) can be established files, folders, modify folder name;
lost63.com original, reprint please indicate the source. AC qq:35501547
*/
$path = $DOCUMENT _root;
$path =str_replace ("/", "\ \", $path);
Specify folder
$path = $path. " \\";
if ($_get[' folder '])
{
$path. =$_get[' folder ']. " \\";
}
This page path, the following will be used when passed back;
$url =$_server[' php_self '];
If it is a folder, the link will be added;
Function folder ($path, $str)
{
if (filetype ($path. $str) = = "Dir")
{
Return "<a href=\" folder= ". $_get[' folder '." \ ". $str." \ "> $str </a>";
}else{
return $str;
}
}
Switch ($_get[' action ')]
{
Case "Del";
if ($_get[' type ']== "file")
{
Unlink ($_get[' path '));
}else{
RmDir ($_get[' path '));
}
echo "<script type=\" text/javascript\ ">alert (' Congratulations, delete success! '); Location.href=\ "". $url. " \ ";</script>";
Break
Case "edit";
if ($_get[' type ']== "file")
{
$file =fopen ($_get[' path '), "R");
while (!feof ($file))
{
$result. =fgets ($file, 9999);
}
Fclose ($file);
Echo ' <form name= ' Form1 ' method= ' post ' action= ' action=editsave&path= '. $_get[' path '. ' &type= '. $_get[' type '. ' >
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" >
<tr>
<TD height= bgcolor= "#99CC00" >>><strong> Edit file </strong> > <a href= "'. $url. '" > Return </a></td>
</tr>
<tr>
<TD height= "O" align= "left" bgcolor= "#FFFFCC" >-> filename: '. $_get[' path '. ' </td>
</tr>
<tr>
<TD align= "center" bgcolor= "#FFFFFF" ><textarea name= "textarea" cols= "135" rows= ">". $result. ' </textarea></td>
</tr>
<tr>
<TD align= "center" bgcolor= "#FFFFFF" ><input type= "Submit" name= "Submission" value= "submitted" >
<input type= "reset" name= "Submit2" value= "reset" ></td>
</tr>
</table>
</form> ';
}else{
Echo ' <form name= ' Form1 ' method= ' post ' action= ' action=dir_rename&path= '. $_get[' path '. ' &type= '. $_get[' type '. ' >
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" >
<tr>
<TD height= bgcolor= "#99CC00" >>><strong> new file </strong> > <a href= "'. $url. '" > Return </a></td>
</tr>
<tr>
<TD height= "align=" "left" bgcolor= "#FFFFCC" >-> folder renamed:
<input name= "filename" type= "text" value= "'. $_get[' path '." "Size=" ></td>
</tr>
<tr>
<TD align= "center" bgcolor= "#FFFFFF" ><input type= "Submit" name= "Submission" value= "submitted" >
<input type= "reset" name= "Submit2" value= "reset" ></td>
</tr>
</table>
</form> ';
}
Break
Case "Editsave";
$file =fopen ($_get[' path '], "w");
Fwrite ($file, $_post[' textarea ']);
Fclose ($file);
echo "<script type=\" text/javascript\ ">alert (' Congratulations, edit success! '); Location.href=\ "". $url. " \ ";</script>";
Break
Case "AddFile";
Echo ' <form name= ' Form1 ' method= ' post ' action= ' action=filesave&path= '. $_get[' path '. ' >
<table width= "100%" border= "0" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" >
<tr>
<TD height= bgcolor= "#99CC00" >>><strong> new file </strong> > <a href= "'. $url. '" > Return </a></td>
</tr>
<tr>
<TD height= "align=" "left" bgcolor= "#FFFFCC" >-> filename:
<input name= "filename" type= "text" value= "'. $_get[' path '." "Size=" ></td>
</tr>
<tr>
<TD align= "center" bgcolor= "#FFFFFF" ><textarea name= "textarea" cols= "135" rows= "M" > Input
</textarea></td>
</tr>
<tr>
<TD align= "center" bgcolor= "#FFFFFF" ><input type= "Submit" name= "Submission" value= "submitted" >
<input type= "reset" name= "Submit2" value= "reset" ></td>
</tr>
</table>
</form> ';
Break
Case "FileSave";
Include points to create a file, otherwise create a folder
if (Strpos ($_post[' filename '], "."))
{
$file =fopen ($_post[' filename '], "w");
Fwrite ($file, $_post[' textarea ']);
Fclose ($file);
}else{
If the folder exists, it exits and does not exist!
if (file_exists ($_post[' filename '))
{
Exit
}else{
mkdir ($_post[' filename ')];
}
}
echo "<script type=\" text/javascript\ ">alert (' Congratulations," $_post[' filename '). " Build success! '); Location.href=\ "". $url. " \ ";</script>";
Break
Case "Dir_rename";
Rename ($_get[' path '],$_post[' filename ')];
echo "<script type=\" text/javascript\ ">alert (' Congratulations," $_post[' filename '). " Renamed success! '); Location.href=\ "". $url. " \ ";</script>";
Break
Default
$s =explode ("\ n", Trim (' dir/b/o:gn $path '));
Echo ' <table width= "100%" border= "0" cellpadding= "0" cellspacing= "1" bgcolor= "#CCCCCC" >
<tr>
<TD height= colspan= "4" bgcolor= "#99CC00" >>><strong> file management </strong> > <a href= "? Action=addfile&path= '. $path. ' " > Establish documents </a> > <a href= "'. $url. '" > Return </a></td>
</tr>
<tr>
<TD height= align= "center" bgcolor= "#FFFFCC" > Files/Folders </td>
<TD align= "center" bgcolor= "#FFFFCC" > File Properties </td>
<TD align= "center" bgcolor= "#FFFFCC" > File size </td>
<TD align= "center" bgcolor= "#FFFFCC" > Operations </td>
</tr> ';
foreach ($s as $value)
{
Echo '
<tr>
<TD height= "bgcolor=" #FFFFFF ">". Folder ($path, $value). ' </td>
<TD align= "center" bgcolor= "#FFFFFF >". FileType ($path. $value). ' </td>
<TD align= "Right" bgcolor= "#FFFFFF" > "Round (FileSize ($path. $value)/1024). ' Kb</td>
<TD align= "center" bgcolor= "#FFFFFF" ><a href= "action=edit&path=". $path. ' \ $value. ' &type= '. FileType ($path. $value). ' " > Edit </a> | <a href= "? action=del&path= '. $path. ' \ $value. ' &type= '. FileType ($path. $value). ' Onclick= ' return confirm (\ ' OK delete-> '. $value. ') \');" > Delete </a></td>
</tr> ';
}
echo "</table>";
Break
}
?>