Note: visitFile () has a small number of modifications
Copy codeThe Code is as follows:
<?
// View the objects in the specified folder
$ FileList = array ();
Function visitFile ($ path)
{
Global $ fileList;
$ Path = str_replace ("\", "/", $ path );
$ Fdir = dir ($ path );
While ($ file = $ fdir-> read ())! = False)
{
If ($ file = '.' | $ file = '..') {continue ;}
$ PathSub = preg_replace ("*/{2,} *", "/", $ path. "/". $ file); // replace multiple backslash
$ FileList [] = is_dir ($ pathSub )? $ PathSub. "/": $ pathSub;
If (is_dir ($ pathSub) {visitFile ($ pathSub );}
}
$ Fdir-> close ();
Return $ fileList;
}
?>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Form method = "get">
<?
$ Path = str_replace ("\", "/", $ path );
$ Path = preg_replace ("*/{2,} *", "/", $ path );
?>
Path: <input type = "text" name = "path" id = "path" value = "<? = $ Path;?> "/> <Br>
<Li> disk root directory/</li>
<Li> Local Network./phpMyAdmin </li>
<Li> Local disk file: // C: or C: </li>
<Br>
<Input name = "action" type = "submit" id = "action" value = "view"/>
<Input name = "action" type = "submit" id = "action" value = "delete" onclick = "if (! Confirm ('delete all subfolders and subfolders of '+ path. value +? ') Return false; "/>
</Form>
<?
If (! Empty ($ path )){
$ Path = preg_replace ("*/{2,} *", "/", $ path );
$ Files = visitFile ($ path );
Switch (strtolower ($ _ GET ["action"])
{
Case "view ":
Foreach ($ files as $ key => $ value)
{
Printf ("No. % 4d · % s <br> \ r \ n", $ key + 1, $ value );
}
Break;
Case "delete ":
$ FaileFiles = array ();
Foreach (array_reverse ($ files) as $ value)
{
If (! Unlink ($ value ))
{
Array_push ($ faileFiles, $ value );
}
}
If (! Unlink ($ path) {array_push ($ faileFiles, $ path );}
If (count ($ faileFiles)> 0)
{
Printf ("<br> failed file deletion (% d): <p> \ r \ n", count ($ faileFiles ));
Foreach ($ faileFiles as $ key => $ value)
{
Printf ("No. % 4d · % s <br> \ r \ n", $ key + 1, $ value );
}
}
Break;
}
}
?>