Copy codeThe Code is as follows:
<? Php
/*
Function: (a) delete a file (B) edit a file, and delete a folder on a webpage (c), provided that the folder is empty (d) create a file or folder, modify the folder name;
Lost63.com original, reprinted please indicate the source. Exchange QQ: 35501547
*/
$ Path = $ DOCUMENT_ROOT;
$ Path = str_replace ("/", "\", $ path );
// Specify a folder
$ Path = $ path ."\\";
If ($ _ GET ['folder'])
{
$ Path. = $ _ GET ['folder']. "\";
}
// The path of this page, which will be used when the following is returned;
$ Url = $ _ SERVER ['php _ SELF '];
// If it is a folder, a link is 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, deletion successful! '); 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 = "25" bgcolor = "#99CC00"> <strong> edit file </strong> <a href = "'. $ url. '"> return </a> </td>
</Tr>
<Tr>
<Td height = "25" align = "left" bgcolor = "# FFFFCC">-> file name: '. $ _ GET ['path'].' </td>
</Tr>
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <textarea name = "textarea" cols = "135" rows = "20"> '. $ result. '</textarea> </td>
</Tr>
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <input type = "submit" name = "Submit" value = "submit">
<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 = "25" bgcolor = "#99CC00"> <strong> New File </strong> <a href = "'. $ url. '"> return </a> </td>
</Tr>
<Tr>
<Td height = "25" align = "left" bgcolor = "# FFFFCC">-> folder rename:
<Input name = "filename" type = "text" value = "'. $ _ GET ['path'].'" size = "50"> </td>
</Tr>
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <input type = "submit" name = "Submit" value = "submit">
<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 successful! '); 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 = "25" bgcolor = "#99CC00"> <strong> New File </strong> <a href = "'. $ url. '"> return </a> </td>
</Tr>
<Tr>
<Td height = "25" align = "left" bgcolor = "# FFFFCC">-> File Name:
<Input name = "filename" type = "text" value = "'. $ _ GET ['path'].'" size = "50"> </td>
</Tr>
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <textarea name = "textarea" cols = "135" rows = "20"> input content
</Textarea> </td>
</Tr>
<Tr>
<Td align = "center" bgcolor = "# FFFFFF"> <input type = "submit" name = "Submit" value = "submit">
<Input type = "reset" name = "Submit2" value = "reset"> </td>
</Tr>
</Table>
</Form> ';
Break;
Case "filesave ";
// Create a file if it contains a vertex. Otherwise, create a folder.
If (strpos ($ _ POST ['filename'], ".")
{
$ File = fopen ($ _ POST ['filename'], "w ");
Fwrite ($ file, $ _ POST ['textarea ']);
Fclose ($ file );
} Else {
// Exit if the folder exists. If the folder does not exist, it is created!
If (file_exists ($ _ POST ['filename'])
{
Exit;
} Else {
Mkdir ($ _ POST ['filename']);
}
}
Echo "<script type = \" text/javascript \ "> alert ('Congratulations,". $ _ POST ['filename']. "created successfully! '); Location. href = \ "". $ url. "\"; </script> ";
Break;
Case "dir_rename ";
Rename ($ _ GET ['path'], $ _ POST ['filename']);
Echo "<script type = \" text/javascript \ "> alert ('Congratulations,". $ _ POST ['filename']. "renamed! '); 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 = "# cccccccc">
<Tr>
<Td height = "25" colspan = "4" bgcolor = "#99CC00" >>> <strong> file management </strong> <a href = "? Action = addfile & path = '. $ path. '"> create a file </a> <a href = "'. $ url. '"> return </a> </td>
</Tr>
<Tr>
<Td height = "25" align = "center" bgcolor = "# FFFFCC"> files/folders </td>
<Td align = "center" bgcolor = "# FFFFCC"> file attributes </td>
<Td align = "center" bgcolor = "# FFFFCC"> file size </td>
<Td align = "center" bgcolor = "# FFFFCC"> operation </td>
</Tr> ';
Foreach ($ s as $ value)
{
Echo'
<Tr>
<Td height = "25" 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 (\ 'Confirm to delete-> '. $ value. '\'); "> Delete </a> </td>
</Tr> ';
}
Echo "</table> ";
Break;
}
?>