yii2+ueditor百度富文本编辑器+七牛云单图多图均可

4 篇文章 0 订阅
3 篇文章 0 订阅

ueditor百度富文本版本:1.4.3
yii2七牛云SDK:yii2安装及使用七牛云文件上传

第一步

打开/web/ueditor/php/Uploader.class.php文件在最顶部引入“yii2安装及使用七牛云文件上传”内composer安装的七牛云类库

require(__DIR__ . '/../../../vendor/crazyfd/yii2-qiniu/Qiniu.php');
use crazyfd\qiniu\Qiniu;

引入yii2安装及使用七牛云文件上传内composer安装的七牛云类库

第二步

修改/web/ueditor/php/Uploader.class.php内upFile方法

  /**
     * 上传文件的主处理方法
     * @return mixed
     */
    private function upFile()
    {
        $file = $this->file = $_FILES[$this->fileField];
        if (!$file) {
            $this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND");
            return;
        }
        if ($this->file['error']) {
            $this->stateInfo = $this->getStateInfo($file['error']);
            return;
        } else if (!file_exists($file['tmp_name'])) {
            $this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");
            return;
        } else if (!is_uploaded_file($file['tmp_name'])) {
            $this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");
            return;
        }

        $this->oriName = $file['name'];
        $this->fileSize = $file['size'];
        //原始上传本地方法
        $this->fileType = $this->getFileExt();
        $this->fullName = $this->getFullName();
        $this->filePath = $this->getFilePath();
        $this->fileName = $this->getFileName();
        $dirname = dirname($this->filePath);


        //检查文件大小是否超出限制
        if (!$this->checkSize()) {
            $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
            return;
        }

        //检查是否不允许的文件格式
        if (!$this->checkType()) {
            $this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
            return;
        }

        //创建目录失败
        if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
            $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
            return;
        } else if (!is_writeable($dirname)) {
            $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
            return;
        }
		//重要代码
        //移动文件
        if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败
            $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
        } else { //移动成功
            $this->stateInfo = $this->stateMap[0];
        }
        $accessKey ='';
        $secretKey = '';
        //资源访问域名(在七牛云内配置域名)
        $domain = '';
        //空间名
        $bucket = '';
        //七牛云文件路径
        $qiniufilePath='website/'.date('Ymd',time()).'/';
        $key=$qiniufilePath.$this->fileName;
        //转存七牛云
        $qiniu = new Qiniu($accessKey, $secretKey,$domain, $bucket);
        $filePath =  $this->filePath;
        $qiniu->uploadFile($filePath,$key);
        $url1 = $qiniu->getLink($key);
        $this->fullName=$url1;
        //删除本地图片
        unlink($filePath);
    }

相关阅读

yii2安装及使用七牛云文件上传

YII2将文件上传至七牛云指定目录/文件夹内

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

G佳伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值