本文实例讲述了ThinkPHP5+UEditor图片上传到阿里云对象存储OSS。分享给大家供大家参考,具体如下:
ThinkPHP5使用富文本UEditor,将富文本编辑框内上传在本地的图片,修改到阿里云对象存储OSS
ThinkPHP5加载UEditor ···· 略
UEditor下载:https://ueditor.baidu.com/website/download.html#ueditor
(或本站下载:https://www.jb51.net/codes/56667.html)
阿里云对象存储SDK下载:https://github.com/aliyun/aliyun-oss-php-sdk
一、配置项
ueditor目录:\public\static\admin\lib\ueditor\1.4.3
OSS配置文件目录:\application\config\oos.php
OSS SDK目录:\extend\oos
二、代码
1、OSS配置文件
<"htmlcode"><"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
<"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 (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) "_blank" href="//www.jb51.net/Special/39.htm">ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】