PHP: Simplest way to delete a folder (including its contents)

后端 未结 7 2050
刺人心
刺人心 2020-12-08 14:00

The rmdir() function fails if the folder contains any files. I can loop through all of the the files in the directory with something like this:



        
7条回答
  •  悲&欢浪女
    2020-12-08 14:33

    rrmdir() -- recursively delete directories:

    function rrmdir($dir) { 
      foreach(glob($dir . '/*') as $file) { 
        if(is_dir($file)) rrmdir($file); else unlink($file); 
      } rmdir($dir); 
    }
    

提交回复
热议问题