ThinkPHP5+UEditor图片上传到阿里云对象存储OSS功能示例
ThinkPHP  /  管理员 发布于 8年前   440
本文实例讲述了ThinkPHP5+UEditor图片上传到阿里云对象存储OSS。分享给大家供大家参考,具体如下: ThinkPHP5使用富文本UEditor,将富文本编辑框内上传在本地的图片,修改到阿里云对象存储OSS ThinkPHP5加载UEditor ・・・・ 略 UEditor下载:https://ueditor.baidu.com/website/download.html#ueditor (或本站下载:/codes/56667.html) 阿里云对象存储SDK下载:https://github.com/aliyun/aliyun-oss-php-sdk 一、配置项 ueditor目录:\public\static\admin\lib\ueditor\1.4.3 二、代码 1、OSS配置文件 2、在UEditor下写入Oos.class.php控制器 *注:本人用的是相对路径,请自行对照自己的目录结构替换掉文件引入地址 3、修改UEditor 上传图片的PHP文件,\public\static\admin\lib\ueditor\1.4.3\php\action_crawler.php 更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。 希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
OSS配置文件目录:\application\config\oos.php
OSS SDK目录:\extend\oos 'xxxx', 'accessKeyId' => 'xxxxxxxxxxx', 'accessKeySecret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx', 'bucket' => 'xxxxx', 'uploadurl' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', //个人配置用,上传图片访问头部完整链接];
oos === null){ $config = require realpath(dirname(__FILE__) . '/../../../../../../../') .'/application/config/oos.php'; $this->bucket = $config['bucket']; try { $this->oos = new OssClient($config['accessKeyId'], $config['accessKeySecret'], $config['endpoint'], false); } catch (OssException $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']); }}
$CONFIG['catcherPathFormat'], "maxSize" => $CONFIG['catcherMaxSize'], "allowFiles" => $CONFIG['catcherAllowFiles'], "oriName" => "remote.png");$fieldName = $CONFIG['catcherFieldName'];/* 抓取远程图片 */$list = array();if (isset($_POST[$fieldName])) { $source = $_POST[$fieldName];} else { $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($_SERVER['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));
您可能感兴趣的文章:
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号