A recursive remove directory function for PHP?

前端 未结 7 1038
眼角桃花
眼角桃花 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:34

    What about this?

    foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
            $path->isDir() && !$path->isLink() ? rmdir($path->getPathname()) : unlink($path->getPathname());
    }
    rmdir($dirPath);
    

提交回复
热议问题