A recursive remove directory function for PHP?

前端 未结 7 991
眼角桃花
眼角桃花 2020-11-30 01:48

I am using PHP to move the contents of a images subfolder

GalleryName/images/

into another folder. After the move, I need to del

相关标签:
7条回答
  • 2020-11-30 02:41

    This is the recursive function I've created/modifed and that finally seems to be working. Hopefully there isn't anything too dangerous in it.

    function destroy_dir($dir) { 
        if (!is_dir($dir) || is_link($dir)) return unlink($dir); 
        foreach (scandir($dir) as $file) { 
            if ($file == '.' || $file == '..') continue; 
            if (!destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) { 
                chmod($dir . DIRECTORY_SEPARATOR . $file, 0777); 
                if (!destroy_dir($dir . DIRECTORY_SEPARATOR . $file)) return false; 
            }; 
        } 
        return rmdir($dir); 
    } 
    
    0 讨论(0)
提交回复
热议问题