ueditor图片上传到阿里云oss tp5

本人php开发一枚。最近公司项目用到ueditor富文本上传商品图片等信息,现在要保存到阿里云oss中,这样读取方便,不占用服务器内存

主要改动的文件Uploader.class.php


1.引用阿里云oss库

use OSS\OssClient;
use OSS\Core\OssException;


require_once '../vendor/aliyun-oss-php-sdk/autoload.php';

2.配置阿里云oss信息(替换成自己的配置信息)

        $this->accessKeyId = ';
        $this->accessKeySecret = ';
        $this->endpoint = '';
        $this->bucket = '';

3. 上传到阿里云oss
        $object = 'public' . $this->fullName; //想要保存文件的名称
        $ossClient = new \OSS\OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
        try {
            $return = $ossClient->uploadFile($this->bucket, $object, $file["tmp_name"]);
        } catch (OssException $e) {
            $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE_OSS");
        }

            //如果不删除本地文件 删除或注释这一行
//            unlink($this->filePath);
            $this->stateInfo = $this->stateMap[0]; //成功

用了上面的方法就可以自己调用了,很方便的

猜你喜欢

转载自blog.csdn.net/qq_35349114/article/details/80207887