链街Dcat后台
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.
 
 
 
 

45 lines
1.0 KiB

<?php
namespace App\Admin\Controllers\v3;
use Dcat\Admin\Traits\HasUploadedFile;
class FileController
{
use HasUploadedFile;
public function handle()
{
$disk = $this->disk('oss');
// 判断是否是删除文件请求
if ($this->isDeleteRequest()) {
// 删除文件并响应
return $this->deleteFileAndResponse($disk);
}
// 获取上传的文件
$file = $this->file();
// 获取上传的字段名称
$column = $this->uploader()->upload_column;
$extension = $file->getClientOriginalExtension();
$fileName = md5(uniqid()).'.'.$extension;
$dir = 'goods_images';
$newName = $fileName;
$result = $disk->putFileAs($dir, $file, $newName);
$path = "{$dir}/$newName";
$diskBak = $this->disk('public');
$diskBak->putFileAs($dir, $file, $newName);
return $result
? $this->responseUploaded($path, $disk->url($path))
: $this->responseErrorMessage('文件上传失败');
}
}