You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
<?php
|
|
|
|
namespace App\Console\Commands; // 定义命名空间
|
|
|
|
use Illuminate\Support\Facades\Storage; // 引入 Storage 门面
|
|
|
|
/**
|
|
* 删除文件控制台命令
|
|
*
|
|
* 该命令用于删除所有上传的静态资源文件。
|
|
*/
|
|
class DeleteFile extends BaseCommand
|
|
{
|
|
/**
|
|
* 控制台命令的名称和签名
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'moon:delete'; // 定义命令的名称和签名
|
|
|
|
/**
|
|
* 控制台命令的描述
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Delete all upload static resources'; // 描述该命令的用途
|
|
|
|
/**
|
|
* 创建一个新的命令实例.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct(); // 调用父类构造函数
|
|
}
|
|
|
|
/**
|
|
* 删除静态资源文件
|
|
*
|
|
* 该方法执行删除操作,删除指定的静态资源目录及其内容。
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
// 删除上传列表目录
|
|
Storage::deleteDirectory('public' . DIRECTORY_SEPARATOR . config('web.upload.list')); // 根据配置删除上传列表目录
|
|
|
|
// 删除上传详情目录
|
|
Storage::deleteDirectory('public' . DIRECTORY_SEPARATOR . config('web.upload.detail')); // 根据配置删除上传详情目录
|
|
|
|
// 输出成功信息
|
|
$this->info('delete file success'); // 命令执行成功后的提示信息
|
|
}
|
|
}
|