Delete directory directly, if it is empty directory can be deleted, if not empty directory, this time can only delete the files in the directory, and then delete the directory. I encapsulated a delete function and then called the function directly. Like can be directly used, coding is GBK, use the attention of the code.
<?php
/**
* Created by Phpstorm.
* User:administrator
* DATE:2016/9/10 0010 * time:20:27//
/delete file, delete file internal file, delete
folder
header (" content-type:text/html; CHARSET=GBK ");
function Deldir ($dir) {
$dh =opendir ($dir);
while ($file =readdir ($DH)) {
if ($file!= "." && $file!= "...") {//Judge whether this directory and superior directory
if (!is_dir ($dir.) /". $file)) {
unlink ($dir.) /". $file);
} else{
//Recursive
Deldir ($dir. " /". $file);
}} Closedir ($DH);
if (RmDir ($dir)) {return
true;
} else{return
false;
}
Delete Function End
if (Deldir ("test")) {
echo ' delete file succeeded ';
Die ();
} else
Echo ' delete file failed ';
Die ();
The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.
Recommend a wonderful topic about PHP recursive operation: PHP recursive operation