Delete the 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 called the function directly. Like can be directly used, the code is gbk, use time to pay attention to the Code.
<?PHP/** * Created by Phpstorm. * User:administrator * DATE:2016/9/10 0010 * time:20:27*///Delete files, Delete files inside files, Delete foldersHeader("content-type:text/html; CHARSET=GBK ");functionDeldir ($dir){ $DH=Opendir($dir); while($file=Readdir($DH)){ if($file! = "." &&$file!="..") {//determine If this directory and the parent directoryif(!Is_dir($dir." /".$file)){ unlink($dir." /".$file); }Else{ //RecursiveDeldir ($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();
PHP Learning Notes: Using recursive implementations to delete file directories