tp5 配置 ueditor 范例

2024-03-18 03:38
文章标签 配置 tp5 范例 ueditor

本文主要是介绍tp5 配置 ueditor 范例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

<?php
namespace app\admin\controller;use app\admin\model\Uploads;
use think\Log;
use ueditor\Uploader;class Ueditor extends Base
{//配置信息public $config = ['imageActionName' => 'uploadimage','imageFieldName' => 'upfile','imageMaxSize' => 2048000,'imageAllowFiles' =>[ 0 => '.png',1 => '.jpg', 2 => '.jpeg', 3 => '.gif', 4 => '.bmp',],'imageCompressEnable' => true,'imageCompressBorder' => 1600,'imageInsertAlign' => 'none','imageUrlPrefix' => '','imagePathFormat' => '/uploads/{yyyy}{mm}{dd}/{time}{rand:6}','scrawlActionName' => 'uploadscrawl','scrawlFieldName' => 'upfile','scrawlPathFormat' => '/uploads/{yyyy}{mm}{dd}/{time}{rand:6}','scrawlMaxSize' => 2048000,'scrawlUrlPrefix' => '','scrawlInsertAlign' => 'none','snapscreenActionName' => 'uploadimage','snapscreenPathFormat' => '/uploads/{yyyy}{mm}{dd}/{time}{rand:6}','snapscreenUrlPrefix' => '','snapscreenInsertAlign' => 'none','catcherLocalDomain' =>[0 => '127.0.0.1', 1 => 'localhost', 2 => 'img.baidu.com'],'catcherActionName' => 'catchimage','catcherFieldName' => 'source','catcherPathFormat' => '/uploads/{yyyy}{mm}{dd}/{time}{rand:6}','catcherUrlPrefix' => '','catcherMaxSize' => 2048000,'catcherAllowFiles' =>[ 0 => '.png', 1 => '.jpg', 2 => '.jpeg', 3 => '.gif', 4 => '.bmp'],'videoActionName' => 'uploadvideo','videoFieldName' => 'upfile','videoPathFormat' => '/uploads/{yyyy}{mm}{dd}/{time}{rand:6}','videoUrlPrefix' => '','videoMaxSize' => 102400000,'videoAllowFiles' =>[0 => '.flv', 1 => '.swf', 2 => '.mkv', 3 => '.avi', 4 => '.rm', 5 => '.rmvb', 6 => '.mpeg', 7 => '.mpg', 8 => '.ogg', 9 => '.ogv', 10 => '.mov', 11 => '.wmv', 12 => '.mp4', 13 => '.webm', 14 => '.mp3', 15 => '.wav', 16 => '.mid'],'fileActionName' => 'uploadfile','fileFieldName' => 'upfile','filePathFormat' => '/uploads/{yyyy}{mm}{dd}/{time}{rand:6}','fileUrlPrefix' => '','fileMaxSize' => 51200000,'fileAllowFiles' =>[0 => '.png', 1 => '.jpg', 2 => '.jpeg', 3 => '.gif', 4 => '.bmp', 5 => '.flv', 6 => '.swf', 7 => '.mkv', 8 => '.avi', 9 => '.rm', 10 => '.rmvb', 11 => '.mpeg', 12 => '.mpg', 13 => '.ogg', 14 => '.ogv', 15 => '.mov', 16 => '.wmv', 17 => '.mp4', 18 => '.webm', 19 => '.mp3', 20 => '.wav', 21 => '.mid', 22 => '.rar', 23 => '.zip', 24 => '.tar', 25 => '.gz', 26 => '.7z', 27 => '.bz2', 28 => '.cab', 29 => '.iso', 30 => '.doc', 31 => '.docx', 32 => '.xls', 33 => '.xlsx', 34 => '.ppt', 35 => '.pptx', 36 => '.pdf', 37 => '.txt', 38 => '.md', 39 => '.xml'],'imageManagerActionName' => 'listimage','imageManagerListPath' => '/uploads/','imageManagerListSize' => 20,'imageManagerUrlPrefix' => '','imageManagerInsertAlign' => 'none','imageManagerAllowFiles' =>[0 => '.png', 1 => '.jpg', 2 => '.jpeg', 3 => '.gif', 4 => '.bmp'],'fileManagerActionName' => 'listfile','fileManagerListPath' => '/uploads/','fileManagerUrlPrefix' => '','fileManagerListSize' => 20,'fileManagerAllowFiles' =>[0 => '.png', 1 => '.jpg', 2 => '.jpeg', 3 => '.gif', 4 => '.bmp', 5 => '.flv', 6 => '.swf', 7 => '.mkv', 8 => '.avi', 9 => '.rm', 10 => '.rmvb', 11 => '.mpeg', 12 => '.mpg', 13 => '.ogg', 14 => '.ogv', 15 => '.mov', 16 => '.wmv', 17 => '.mp4', 18 => '.webm', 19 => '.mp3', 20 => '.wav', 21 => '.mid', 22 => '.rar', 23 => '.zip', 24 => '.tar', 25 => '.gz', 26 => '.7z', 27 => '.bz2', 28 => '.cab', 29 => '.iso', 30 => '.doc', 31 => '.docx', 32 => '.xls', 33 => '.xlsx', 34 => '.ppt', 35 => '.pptx', 36 => '.pdf', 37 => '.txt', 38 => '.md', 39 => '.xml']];//ueditor入口public function index(){error_reporting(E_ERROR);header("Content-Type: text/html; charset=utf-8");$action = trim(params('action'));switch ($action) {case 'config':$result =  json_encode(json_decode(json_encode($this->config)));break;/* 上传图片 */case 'uploadimage':/* 上传涂鸦 */case 'uploadscrawl':/* 上传视频 */case 'uploadvideo':/* 上传文件 */case 'uploadfile':$result = $this->_upload($action);break;/* 列出图片 */case 'listimage':$result = $this->_list($action);break;/* 列出文件 */case 'listfile':$result = $this->_list($action);break;/* 抓取远程文件 */case 'catchimage':$result = $this->_crawler();break;default:$result = json_encode(array('state'=> '请求地址出错'));break;}/* 输出结果 */if (isset($_GET["callback"])) {if (preg_match("/^[\w_]+$/", $_GET["callback"])) {echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';} else {echo json_encode(array('state'=> 'callback参数不合法'));}} else {echo $result;}}/*** 上传附件和上传视频* Date: 14-04-09* Time: 上午10:17*/private function _upload($action){/* 上传配置 */$base64 = "upload";switch (htmlspecialchars($action)) {case 'uploadimage':$config = ["pathFormat" => $this->config['imagePathFormat'],"maxSize" => $this->config['imageMaxSize'],"allowFiles" => $this->config['imageAllowFiles']];$fieldName = $this->config['imageFieldName'];break;case 'uploadscrawl':$config = ["pathFormat" => $this->config['scrawlPathFormat'],"maxSize" => $this->config['scrawlMaxSize'],"allowFiles" => $this->config['scrawlAllowFiles'],"oriName" => "scrawl.png"];$fieldName = $this->config['scrawlFieldName'];$base64 = "base64";break;case 'uploadvideo':$config = ["pathFormat" => $this->config['videoPathFormat'],"maxSize" => $this->config['videoMaxSize'],"allowFiles" => $this->config['videoAllowFiles']];$fieldName = $this->config['videoFieldName'];break;case 'uploadfile':default:$config = ["pathFormat" => $this->config['filePathFormat'],"maxSize" => $this->config['fileMaxSize'],"allowFiles" => $this->config['fileAllowFiles']];$fieldName = $this->config['fileFieldName'];break;}/* 生成上传实例对象并完成上传 */$up = new Uploader($fieldName, $config, $base64);/* 返回数据 */$data = $up->getFileInfo();$this->_addInfo($data);return json_encode($data);}/*** 获取已上传的文件列表    * Date: 14-04-09* Time: 上午10:17*/private function _list($action){/* 判断类型 */switch ($action) {/* 列出文件 */case 'listfile':$allowFiles = $this->config['fileManagerAllowFiles'];$listSize = $this->config['fileManagerListSize'];$path = $this->config['fileManagerListPath'];break;/* 列出图片 */case 'listimage':default:$allowFiles = $this->config['imageManagerAllowFiles'];$listSize = $this->config['imageManagerListSize'];$path = $this->config['imageManagerListPath'];}$allowFiles = substr(str_replace(".", "|", join("", $allowFiles)), 1);/* 获取参数 */$size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $listSize;$start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0;$end = $start + $size;/* 获取文件列表 */$path = $_SERVER['DOCUMENT_ROOT'] . (substr($path, 0, 1) == "/" ? "":"/") . $path;$files = $this->_getfiles($path, $allowFiles);if (!count($files)) {return json_encode(array("state" => "no match file","list" => array(),"start" => $start,"total" => count($files)));}/* 获取指定范围的列表 */$len = count($files);for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--){$list[] = $files[$i];}/* 返回数据 */$result = json_encode(array("state" => "SUCCESS","list" => $list,"start" => $start,"total" => count($files)));return $result;}/*** 遍历获取目录下的指定类型的文件* @param $path* @param array $files* @return array*/private function _getfiles($path, $allowFiles, &$files = array()){if (!is_dir($path)) return null;if(substr($path, strlen($path) - 1) != '/') $path .= '/';$handle = opendir($path);while (false !== ($file = readdir($handle))) {if ($file != '.' && $file != '..') {$path2 = $path . $file;if (is_dir($path2)) {$this->_getfiles($path2, $allowFiles, $files);} else {if (preg_match("/\.(".$allowFiles.")$/i", $file)) {$files[] = array('url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])),'mtime'=> filemtime($path2));}}}}return $files;}/*** 抓取远程图片     * Date: 14-04-14* Time: 下午19:18*/private function _crawler(){set_time_limit(0);/* 上传配置 */$config = array("pathFormat" => $this->config['catcherPathFormat'],"maxSize" => $this->config['catcherMaxSize'],"allowFiles" => $this->config['catcherAllowFiles'],"oriName" => "remote.png");$fieldName = $this->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();$data = ["state" => $info["state"],"url" => $info["url"],"size" => $info["size"],"title" => htmlspecialchars($info["title"]),"original" => htmlspecialchars($info["original"]),"source" => htmlspecialchars($imgUrl)];array_push($list, $data);$this->_addInfo($data);}/* 返回抓取数据 */return json_encode(array('state'=> count($list) ? 'SUCCESS':'ERROR','list'=> $list));}//保存文件信息private function _addInfo($info){$record = ['admin_id' => !empty($this->administrator['id'])?$this->administrator['id']:0,'extension' => !empty($info['type'])?str_replace('.','',$info['type']):'','save_name' => !empty($info['url'])?str_replace('/uploads/','',$info['url']):'','filename' => !empty($info['title'])?$info['title']:'','size' => !empty($info['size'])?$info['size']:0,'create_time' => TIMESTAMP];//数据库存入失败记录日志if(!Uploads::addInfo($record)){Log::error(__FILE__.':'.__LINE__.' 错误:'.$record['save_name'].'数据库记录失败');}}
}

 

这篇关于tp5 配置 ueditor 范例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/821084

相关文章

Zookeeper安装和配置说明

一、Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式。 ■ 单机模式:Zookeeper只运行在一台服务器上,适合测试环境; ■ 伪集群模式:就是在一台物理机上运行多个Zookeeper 实例; ■ 集群模式:Zookeeper运行于一个集群上,适合生产环境,这个计算机集群被称为一个“集合体”(ensemble) Zookeeper通过复制来实现

CentOS7安装配置mysql5.7 tar免安装版

一、CentOS7.4系统自带mariadb # 查看系统自带的Mariadb[root@localhost~]# rpm -qa|grep mariadbmariadb-libs-5.5.44-2.el7.centos.x86_64# 卸载系统自带的Mariadb[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7

hadoop开启回收站配置

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。 开启回收站功能参数说明 (1)默认值fs.trash.interval = 0,0表示禁用回收站;其他值表示设置文件的存活时间。 (2)默认值fs.trash.checkpoint.interval = 0,检查回收站的间隔时间。如果该值为0,则该值设置和fs.trash.interval的参数值相等。

NameNode内存生产配置

Hadoop2.x 系列,配置 NameNode 内存 NameNode 内存默认 2000m ,如果服务器内存 4G , NameNode 内存可以配置 3g 。在 hadoop-env.sh 文件中配置如下。 HADOOP_NAMENODE_OPTS=-Xmx3072m Hadoop3.x 系列,配置 Nam

wolfSSL参数设置或配置项解释

1. wolfCrypt Only 解释:wolfCrypt是一个开源的、轻量级的、可移植的加密库,支持多种加密算法和协议。选择“wolfCrypt Only”意味着系统或应用将仅使用wolfCrypt库进行加密操作,而不依赖其他加密库。 2. DTLS Support 解释:DTLS(Datagram Transport Layer Security)是一种基于UDP的安全协议,提供类似于

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

沁恒CH32在MounRiver Studio上环境配置以及使用详细教程

目录 1.  RISC-V简介 2.  CPU架构现状 3.  MounRiver Studio软件下载 4.  MounRiver Studio软件安装 5.  MounRiver Studio软件介绍 6.  创建工程 7.  编译代码 1.  RISC-V简介         RISC就是精简指令集计算机(Reduced Instruction SetCom

log4j2相关配置说明以及${sys:catalina.home}应用

${sys:catalina.home} 等价于 System.getProperty("catalina.home") 就是Tomcat的根目录:  C:\apache-tomcat-7.0.77 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" /> 2017-08-10

DM8数据库安装后配置

1 前言 在上篇文章中,我们已经成功将库装好。在安装完成后,为了能够更好地满足应用需求和保障系统的安全稳定运行,通常需要进行一些基本的配置。下面是一些常见的配置项: 数据库服务注册:默认包含14个功能模块,将这些模块注册成服务后,可以更好的启动和管理这些功能;基本的实例参数配置:契合应用场景和发挥系统的最大性能;备份:有备无患;… 2 注册实例服务 注册了实例服务后,可以使用系统服务管理,

配置InfiniBand (IB) 和 RDMA over Converged Ethernet (RoCE) 网络

配置InfiniBand (IB) 和 RDMA over Converged Ethernet (RoCE) 网络 服务器端配置 在服务器端,你需要确保安装了必要的驱动程序和软件包,并且正确配置了网络接口。 安装 OFED 首先,安装 Open Fabrics Enterprise Distribution (OFED),它包含了 InfiniBand 所需的驱动程序和库。 sudo