thinkphp5 基于百度的ueditor前端插件上传图片到阿里云oss
1,下载阿里云集成包 composer require aliyuncs/oss-sdk-php 2,找到ueditor目录下的php下面的Upload.class.php里面的upFile大概在110行+的 //创建目录失败 //移动文件 这两部分的代码全部注释掉,换成下面的代码 //oss设置 $ossconfig = [ 'KeyId' => 'xxx', 'KeySecret' => 'xxx', 'Endpoint' => 'xxxx', 'Bucket' => 'xxx', 'url' => 'xxxx',//图片完整路径的域名 ]; //获取文件后缀 $file_type = substr($this->filePath, strrpos($this->filePath, '.')); //得到今天日期 $today = date('Ymd', time()); //得到文件名 $file_name = 'image/'.$today.'/'.$this->fileName; //$ossconfig为获取OSS的配置信息 //$ossconfig = $this->getOssApi(); //实例化OSS $ossClient = new OssClient($ossconfig['KeyId'], $ossconfig['KeySecret'], $ossconfig['Endpoint']); try { //执行阿里云上传 $result = $ossClient->uploadFile($ossconfig['Bucket'], $file_name, $file["tmp_name"]); //赋给图片路径(原代码) //$this->fullName = $result['info']['url']; //获得上传之后访问该图片的路径 $endpoint = str_replace('http://', '', $ossconfig['Endpoint']); $this->ossimgurl = "https://".$ossconfig['Bucket'].".".$endpoint."/".$file_name;//ossimgurl这是自定义属性,避免以ueditor方式获得图片地址 $this->fullName = $ossconfig['url']."/".$file_name; $this->stateInfo = $this->stateMap[0]; } catch (\OSS\Core\OssException $e) { //$this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE"); //将错误信息修改为阿里云上传失败的错误信息 $this->stateInfo = $e->getMessage(); }