With this applet, Phper will 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 Browsing folder directory, and then delete.
Code One:
Copy Code code as follows:
<?php
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 is from the manual:
Code two:
Copy Code code as follows:
<?php
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 <br>";
}
}
}
Closedir ($handle);
RmDir ($dir);
echo "Removing$dir<br>";
}
}
The third one is collected on the codebit.cn or in the manual.
Code Three:
Copy Code code 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);
}
?>