欢迎指正!/** * Application: 清空目录 * @param $sourcePath 目录句柄 如'/path/to/sourceDir' * Created on 2018/6/13 9:09 * Created by zhouzhimin */ public static function delDir($sourcePath) { $dh = opendir($sourcePath); while (false !== ($file = readdir($dh))) { if ($file != "." && $file != "..") { $fullPath = $sourcePath . '/' . $file; if (!is_dir($fullPath)) { unlink($fullPath); } elseif (is_dir($fullPath)) { self::delDir($fullPath); } } } closedir($dh); rmdir($sourcePath); }
分享一个PHP递归清空目录(包含子目录与子目录下文件)
最新推荐文章于 2021-07-05 14:19:27 发布