首页 > 作文

ThinkPHP5+UEditor图片上传到阿里云对象存储OSS功能示例

更新时间:2023-04-07 14:06:09 阅读: 评论:0

本文实例讲述了thinkphp5+ueditor图片上传到阿里云对象存储oss。分享给大家供大家参考,具体如下:

thinkphp5使用富文本ueditor,将富文本编辑框内上传在本地的图片,修改到阿里云对象存储oss

thinkphp5加载ueditor ···· 略

ueditor下载:

(或本站下载:)

阿里云对象存储sdk下载:

一、配置项

ueditor目录:\public\sta极限挑战3tic\admin\lib\ueditor\1.4.3
oss配置文件目录:\application\config\oos.php
oss sdk目录:\extend\oos

二、代码

1、oss配置文件

<?phpreturn [  'endpoint' => 'xxxx',  'accesskeyid' => 'xxxxxxxxxxx',  'accesskeycret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',什么专业赚钱  'bucket' => 'xxxxx',  'uploadurl' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', //个人配置用,上传图片访问头部完整山东招生教育考试院链接];

2、在ueditor下写入oos.class.php控制器

*注:本人用的是相对路径,请自行对照自己的目录结构替换掉文件引入地址

<?phprequire_once realpath(dirname(__file__) . '/../../../../../../../') . '/extend/oos/autoload.php';u oss\ossclient;u oss\core\osxception;class oos{  protected $oos = null;  protected $bucket = null;  //获取oos客户端  protected function getossclient(){    if($this->oos === null){      $config = require realpath(dirname(__file__) . '/../../../../../../../') .'/application/config/oos.php';      $this->bucket = $config['bucket'];      try {        $this->oos = new ossclient($config['accesskeyid'], $config['accesskeycret'], $config['endpoint'], fal);      } catch (osxception $e) {        printf(__function__ . "creating ossclient instance: failed\n");        printf($e->getmessage() . "\n");        return null;      }    }    return $this->oos;  }  //上传  public function upload($海水鱼file,$save){    $config = require realpath(dirname(__file__) . '/../../../../../../../') .'/application/config/oos.php';    $save = 'upload/'.$save;    $ossclient = $this->getossclient();    if (is_null($ossclient)) exit('链接存储失败');    $result = $ossclient->uploadfile($this->bucket, $save, $file);    return !empty($result['x-oss-request-id']);  }}

3、修改ueditor 上传图片的php文件\public\static\admin\lib\ueditor\1.4.3\php\action_crawler.php

<?php/** * 抓取远程图片 * ur: jinqn * date: 14-04-14 * time: 下午19:18 */t_time_limit(0);include("uploader.class.php");include("oos.class.php");// 引入oss对象$oos_config = require realpath(dirname(__file__) . '/../../../../../../../') .'/application/config/oos.php';$oos = new oos();/* 上传配置 */$config = array(  "pathformat" => $config['catcherpathformat'],  "maxsize" => $config['catchermaxsize'],  "allowfiles" => $config['catcherallowfiles'],  "oriname" => "remote.png");$fieldname = $config['catcherfieldname'];/* 抓取远程图片 */$list = array();if (ist(蝶恋花 答李淑一$_post[$fieldname])) {  $source = $_post[$fieldname];} el {  $source = $_get[$fieldname];}foreach ($source as $imgurl) {  $item = new uploader($imgurl, $config, "remote");  $info = $item->getfileinfo();  $year = date('ymd',time());//图片路径 (年/月) 自己设置  $img_name = time().rand(1,1000).$info['type'];  $bos_url = "ueditor_upload/xinjieshi/image/$year/$img_name";//用作保存的图片路径和名字  $oos->upload($_rver['document_root'].'/'.$info['url'],$bos_url);  array_push($list, array(    "state" => $info["state"],    "url" => $oos_config['uploadurl'].$bos_url,    "size" => $info["size"],    "title" => htmlspecialchars($info["title"]),    "original" => htmlspecialchars($info["original"]),    "source" => htmlspecialchars($imgurl)  ));}/* 返回抓取数据 */return json_encode(array(  'state'=> count($list) ? 'success':'error',  'list'=> $list));

本文发布于:2023-04-07 14:06:07,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/be84580229a01a1c6b8bb4e0a733fda6.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:ThinkPHP5+UEditor图片上传到阿里云对象存储OSS功能示例.doc

本文 PDF 下载地址:ThinkPHP5+UEditor图片上传到阿里云对象存储OSS功能示例.pdf

标签:阿里   图片   对象   目录
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图