A general method to implement recursive deletion of directories in PHP

WBOY
Release: 2016-07-25 08:45:29
Original
1007 people have browsed it
  1. /**
  2. *
  3. +------------------------------------------------- -----------------------
  4. * Description Recursively delete directories
  5. +-------------------------- ------------------------------------------------
  6. * @param string $dir The directory to be deleted
  7. +--------------------------------------------- --------------------------------
  8. * @return If the directory does not exist or is deleted successfully, it will return TRUE
  9. +--- -------------------------------------------------- ---------------
  10. * @author gongwen
  11. +---------------------------- ----------------------------------------
  12. */
  13. function rmdirs($dir){
  14. if (!is_dir($dir) || rmdir($dir)) return TRUE;
  15. if($dir_handle=opendir($dir)){
  16. while($filename=readdir($dir_handle)){
  17. if($filename!='.' && $filename!='..'){
  18. $subFile=$dir.'/'.$filename;
  19. }
  20. is_dir($subFile)?rmdirs($subFile):unlink($subFile);
  21. }
  22. closedir($dir_handle);
  23. return rmdir($dir);
  24. }
  25. }
复制代码

PHP


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template