From 7bd7c7d7298bc4cf03a8c249037d2cf0977ae44b Mon Sep 17 00:00:00 2001 From: Chaim Date: Fri, 17 Apr 2020 15:36:24 +0800 Subject: [PATCH] - update Files.php --- src/Files.php | 30 +++++++++++++++++++++++++++++- src/facade/Files.php | 3 ++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Files.php b/src/Files.php index 947ab15..4f085a1 100644 --- a/src/Files.php +++ b/src/Files.php @@ -26,7 +26,7 @@ class Files { /** * 删除文件 - * @param string $name + * @param string $name 路径 * @return bool */ public function delete(string $name) @@ -34,4 +34,32 @@ class Files if (file_exists($name)) if (unlink($name)) return true; return false; } + + /** + * 删除文件夹 + * @param string $name 路径 + * @return bool + */ + public function deletes(string $name) + { + //先删除目录下的文件: + $dh = opendir($name); + while ($file = readdir($dh)) { + if ($file != "." && $file != "..") { + $fullpath = $name . "/" . $file; + if (!is_dir($fullpath)) { + unlink($fullpath); + } else { + $this->deletes($fullpath); + } + } + } + closedir($dh); + //删除当前文件夹: + if (rmdir($name)) { + return true; + } else { + return false; + } + } } diff --git a/src/facade/Files.php b/src/facade/Files.php index f10f6f5..c22d8ec 100644 --- a/src/facade/Files.php +++ b/src/facade/Files.php @@ -25,7 +25,8 @@ use think\Facade; * @package think\facade * @mixin \DtApp\ThinkLibrary\Files * - * @method \DtApp\ThinkLibrary\Files delete(string $name) bool 编码 + * @method \DtApp\ThinkLibrary\Files delete(string $name) bool 删除文件 + * @method \DtApp\ThinkLibrary\Files deletes(string $name) bool 删除文件夹 */ class Files extends Facade {