{{userInfo.nickname}}
用户设置 退出登录

{{wikiTitle}}

上传扩展

目前已有本地上传、阿里云OSS上传、腾讯云COS上传、七牛云上传扩展

扩展入口文件

文件目录 crmeb\services\upload\Upload.php

namespace crmeb\services\upload;

use crmeb\basic\BaseManager;
use think\facade\Config;

/**
 * Class Upload
 * @package crmeb\services\upload
 * @mixin \crmeb\services\upload\storage\Local
 * @mixin \crmeb\services\upload\storage\OSS
 * @mixin \crmeb\services\upload\storage\COS
 * @mixin \crmeb\services\upload\storage\Qiniu
 */
class Upload extends BaseManager
{
    //...
}

使用上传扩展

use crmeb\services\upload\Upload;

$upload = new Upload();

//上传文件
$path = '上传目录';
//validate() 方法为验证上传
//move() 调用move方法进行上传
$res = $upload->to($path)->validate()->move();

//上传文件流
$fileContent = '文件流内容';
$res = $upload->to($path)->validate()->stream($fileContent);

//上传文件流不验证文件
$res = $upload->to($path)->stream($fileContent);

获取第三方上传桶列表

$type 1=本地上传,2=七牛云、3=阿里云oss、4=腾讯云cos

use app\services\other\UploadService;

//切换到阿里云oss上传
$type = 3;

$upload = UploadService::init($type);

//获取桶列表
$list = $upload->listbuckets();

var_dump($list);

/*
[
    {
        "name":"桶名",
        "location":"区域",
        "createTime":"创建时间",
    }
]
*/

创建第三方上传扩展桶

use app\services\other\UploadService;

//切换到阿里云oss上传
$type = 3;

$upload = UploadService::init($type);

//创建桶
$res = $upload->createBucket('test-bucket-oss');

if (false === $res) {
    var_dump($upload->getError());
} else {
    //创建成功
}

使用系统自带封装服务

use app\services\other\UploadService;

//根据系统设置自动实例化上传类
$upload = UploadService::init();
//执行上传
$path = '';
$res = $upload->to($path)->validate()->move();

//上传失败
if (false === $res) {
    var_dump($upload->getError());
} else {
    var_dump($res->uploadInfo); //上传文件信息
    var_dump($res->realName); //文件真实名称
    var_dump($res->fileName); //文件上传后的名称
    var_dump($res->filePath); //文件上传后的路径地址
}
{{cateWiki.like_num}}人点赞
0人点赞
评论({{cateWiki.comment_num}}) {{commentWhere.order ? '评论从旧到新':'评论从新到旧'}} {{cateWiki.page_view_num}}人看过该文档
评论(0) {{commentWhere.order ? '评论从旧到新':'评论从新到旧'}} 40人看过该文档
评论
{{item.user ? item.user.nickname : ''}} (自评)
{{item.content}}
{{item.create_time}} 删除
{{item.like ? item.like.like_num : 0}} {{replyIndex == index ? '取消回复' : '回复'}}
评论
{{items.user ? items.user.nickname : '暂无昵称'}} (自评)
{{items.content}}
{{items.create_time}} 删除
{{items.like ? items.like.like_num : 0}} {{replyIndexJ == (index+'|'+indexJ) ? '取消回复' : '回复'}}
评论
目录
  • {{item}}