- update Files.php

v6
Chaim 4 years ago
parent fa7ccfd9a7
commit 7bd7c7d729

@ -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;
}
}
}

@ -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
{

Loading…
Cancel
Save