With this applet, phper do not have to manually delete the directory files on the computer, in the practice of PHP directory file operation can use this function, on this basis can also increase the Browse folder directory, and then delete.
Code One:
Copy CodeThe code is as follows:
function D_rmdir ($dirname) {//Delete non-empty directory
if (!is_dir ($dirname)) {
return false;
}
$handle = @opendir ($dirname);
while (($file = @readdir ($handle))!== false) {
if ($file! = '. ' && $file! = ' ... ') {
$dir = $dirname. '/' . $file;
Is_dir ($dir)? D_rmdir ($dir): unlink ($dir);
}
}
Closedir ($handle);
return rmdir ($dirname);
}
if (D_rmdir ("./temp"))
echo "Succes";
Else
echo "false";
?>
The second one was flipped out from the manual:)
Code two:
Copy CodeThe code is as follows:
Functionremove_directory ($dir) {
if ($handle =opendir ("$dir")) {
while (false!== ($item =readdir ($handle))) {
if ($item! = "." && $item! = "...") {
if (Is_dir ("$dir/$item")) {
Remove_directory ("$dir/$item");
}else{
Unlink ("$dir/$item");
echo "removing$dir/$item
";
}
}
}
Closedir ($handle);
RmDir ($dir);
echo "Removing$dir
";
}
}
The third one is codebit.cn, or the manual.
Code Three:
Copy CodeThe code is as follows:
Functionremovedir ($dirName)
{
if (!is_dir ($dirName))
{
Returnfalse;
}
$handle = @opendir ($dirName);
while (($file = @readdir ($handle))!==false)
{
if ($file! = '. ') && $file! = ' ... ')
{
$dir = $dirName. ' /'. $file;
Is_dir ($dir)? RemoveDir ($dir): @unlink ($dir);
}
}
Closedir ($handle);
Returnrmdir ($dirName);
}
?>
http://www.bkjia.com/PHPjc/326565.html www.bkjia.com true http://www.bkjia.com/PHPjc/326565.html techarticle with this small program, phper do not have to manually delete the directory files on the computer, in the practice of PHP directory file operation can use this function, on this basis can also increase the ...