服务器搭建微信编辑器,ueditor编辑器实现微信上传和图片服务器上传
如题。
前端部分:
var ue = UE.getEditor('container', {
serverUrl:'{pigcms::$f_siteUrl}<?php echo U("Home/Upload/UeditorUpload"); ?>'
});
ue.ready(function() {
ue.execCommand('serverparam', {
'token': '{pigcms::$token}',
'isTuwen':1,
});
});
后端部分:
class UploadAction extends BaseAction {
public $token;
public function _initialize() {
parent::_initialize();
$this->token=$this->_session('token');
if (!$this->token){
$this->token='admin';
}
}
/**
* 自定义ueditor文件上传
*/
public function UeditorUpload(){
switch($_GET['action']){
case 'config':
$config = C('ueditor_config');
echo json_encode($config);
exit;
break;
case 'uploadimage':
if($_GET['isTuwen'] == 1){
$token = $_GET['token'];
$wxuser = M('Wxuser')->where(array('token'=>$token))->find();
if(!empty($wxuser)){
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 实例化上传类
$upload->maxSize = intval(C('up_size'))*1024;// 设置附件上传大小
$upload->allowExts = explode(',',C('up_exts'));// 设置附件上传类型
$upload->savePath = C('up_path');// 设置附件上传目录
if(!$upload->upload()) {// 上传错误提示错误信息
$re = array();
$re['state'] = $upload->getErrorMsg();
echo json_encode($re);
exit;
}else{// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
}
$pic_path = $info['0']['savepath'].$info['0']['savename'];
$data['media']='@'.realpath($pic_path);
$weouth_new = new Weouth_new($wxuser['appid']);
$result = $weouth_new->uploadForeverMedia($data, 'image');
unlink(realpath($pic_path));//删除已上传的图片
if($result){
$re = array();
$re['state'] = "SUCCESS";
$re['url'] = $result['url'];
$re['title'] = $_FILES['upfile']['name'];
$re['original'] = $result['url'];
}else{
$re = array();
$re['state'] = $weouth_new->errMsg;
}
}
echo json_encode($re);
exit;
}else{
$return=$this->localUpload();
if($return['error']){
$re = array();
$re['state'] = $return['msg'];
}else{
$re = array();
$re['state'] = "SUCCESS";
$re['url'] = $return['msg'];
$re['title'] = $_FILES['upfile']['name'];
$re['original'] = $return['msg'];
}
echo json_encode($re);
exit;
}
break;
}
}
public function upload(){
if (!function_exists('imagecreate')){
exit('php不支持gd库,请配置后再使用');
}
if (IS_POST){
$return=$this->localUpload();
echo "";
echo("");
exit();
}
}
/**
* 线上上传方法
*/
public function uploadImg(){
$return=$this->localUpload();
if ($return['error']){
$this->alert($return['msg']);
}else {
header('Content-type: text/html; charset=UTF-8');
echo json_encode(array('status' => 1, 'path' => $return['msg'],'small_path'=>$return['small'],'filename'=>$return['filename']));
exit;
}
}
/**
* 线上上传音乐
*/
public function uploadMusic(){
$return=$this->localUpload('mp3');
if ($return['error']){
$this->alert($return['msg']);
}else {
header('Content-type: text/html; charset=UTF-8');
echo json_encode(array('status' => 1, 'path' => $return['msg'],'small_path'=>$return['small'],'filename'=>$return['filename']));
exit;
}
}
public function localUpload($filetypes=''){
$file_input_name="";
$file_info=array();
foreach ($_FILES as $key=>$file){
if(!empty($file['name'])) {
$file_input_name=$key;
$file_info['size']=$file['size'];
$pathinfo = pathinfo($file['name']);
$file_info['extension']=$pathinfo['extension'];
break;
}
}
if($file_input_name){
$uf = new UploadFile_new($file_input_name);
$uf->setMaxSize(intval(C('up_size'))) ;//KB
if (!$filetypes){
$upload_allowExts = implode("|",explode(',',C('up_exts')));
}else {
$upload_allowExts = $filetypes;
}
$uf->setFileType($upload_allowExts);
if (isset($_POST['width'])&&intval($_POST['width'])){
$isneed_Resize=true;
$uf->setResizeImage(true);
$uf->setResizeWidth($_POST['width']);
$uf->setResizeHeight($_POST['height']);
}
$uf->setUploadType("ftp");//设置上传方式,默认为程序上传
$uf->setShowAsChinese(true);
if(($rtnMSG=$uf->upload())=="success")
{
$error=0;
if($isneed_Resize){
$msg = $uf->getResizeImageURL();
}else{
$msg = $uf->getSaveFileURL();
}
$filename=$uf->getFileName();
$small_img_URL= $uf->getResizeImageURLForMobile();
}else{
$error=1;
$msg=$rtnMSG;
$small_img_URL='';
}
}else{
$error=1;
$small_img_URL='';
$msg="请选择图片";
}
return array('error'=>$error,'msg'=>$msg,'small'=>$small_img_URL,'filename'=>$filename);
}
public function alert($msg) {
header('Content-type: text/html; charset=UTF-8');
echo json_encode(array('error' => 1, 'message' => $msg));
exit;
}
/**
* 线下上传图片
*/
public function uploadImg_test(){
$path = '';
$result = array();
import('@.ORG.Util.Upload');
$uf = new Upload('Filedata');//file
$uf->setMaxSize(102400);
$uf->setUploadType("ftp");
$uf->setServerSite('20');
$uf->setSaveDir("/klf/users/album/");
$uf->setResizeReality(true);
$rtnMSG=$uf->doupload();
if($rtnMSG=="success"){
$path=$uf->getSaveFileURL();
$filename=$uf->getFileName();
//wss 获取上传名称
$result = array('status'=>"1",'path'=>$path,'filename'=>$filename);
echo json_encode($result);
die();
}else{
$result = array('status'=>"0",'path'=>$path);
echo json_encode($result);
die();
}
}
}
服务器搭建微信编辑器,ueditor编辑器实现微信上传和图片服务器上传相关推荐
- java 图片服务器 上传_Java实现把图片上传到图片服务器(nginx+vsftp)
前言: 在我另一篇笔记中已经记载了如何用nginx + vsftp搭建图片服务器(请参考nginx + vsftp搭建图片服务器),并且用vsftp的客户端工具filezilla测试过已经可用.但是在 ...
- Java实现把图片上传到图片服务器(nginx+vsftp)
在我另一篇笔记中已经记载了如何用nginx + vsftp搭建图片服务器,并且用vsftp的客户端工具filezilla测试过已经可用.但是在开发中应该是把用户在前端页面提交的图片保存到图片服务器中, ...
- java分布式实现图片上传到图片服务器
java分布式实现图片上传到图片服务器 操作步骤 第一步 第二步 第三步 第四步 第五步 第六步 代码实现 第七步 JS代码 大功告成!! 操作步骤 第一步 在页面中的form表单里面增加一个inpu ...
- php 怎么上传图片,php怎么把图片上传到图片服务器
php怎么把图片上传到图片服务器? 图片服务器代码<?php /** * 图片服务器上传API接口 * by Zx * date 2016-04-28 */ header('Content-ty ...
- 服务器上文件不能编辑器,UEditor 编辑器常见问题解决
ueditor单图上传图片显示上传错误/多图上传显示服务器错误,实际上图片已经传到服务器或者本地 1.这个问题是因为ueditor里面的Upload.class.php里面__construct()方 ...
- 淘淘商城第三天—完成商品添加功能 商品类目选择 图片上传 图片服务器搭建 kindEditor富文本编辑器的使用 商品添加功能
1.实现商品类目选择功能 1.1需求 在商品添加页面,点击"选择类目"显示商品类目列表: 请求初始化树形控件的url:/item/cat/list 1.2 EasyUI tree数 ...
- SSH2项目引入百度富文本编辑器Ueditor编辑器
转:https://blog.csdn.net/a281246240/article/details/50587337 一.整合所需UEditor原代码 这个可以到http://ueditor.bai ...
- uni-app开发微信小程序(获取多张本地相册图片并上传到服务器功能)
思路: 用户触发某一事件弹出一个弹窗(用户可能直接手机拍摄或者直接从手机相册选择照片),用户选择完方式后,调用对应的api并把选择好的照片上传到服务器. 涉及到的API: 1.uni.showActi ...
- azure云服务器搭建连接_如何创建到Azure SQL数据库的链接服务器
azure云服务器搭建连接 Linked servers allow to access data from another SQL Server or another data source (e. ...
最新文章
- Mac Vim 如何设置高亮
- Linux 用户组相关命令
- Linux系统安全学习手册
- 每日 30 秒 ⏱ HTML Cosplay
- TCP 协议的三次握手、四次分手
- websocket学习总结记录
- python 异常回溯_关于python:在循环中捕获异常回溯,然后在脚本末尾引发错误...
- edpluse怎么运行c语言,[JSP]小菜也来学Editplus+Tomcat配置jsp运行环境
- 比特币余额大于1BTC的地址数量较二月下降5048个
- ngx_pagespeed 的魔力
- 陷阱:使用==来比较原始的包装器对象,如Integer
- 图解形态学Morphological
- fiddler抓包手机app数据(手机连接WiFi)
- JavaScript实现类似百度的智能搜索框
- 计算机碎片整理的作用,磁盘碎片整理有什么用,详细教您磁盘碎片整理有什么作用...
- pytorch中批量归一化BatchNorm1d和BatchNorm2d函数
- 入职体检(三甲医院)
- 计算机c盘一直减小咋办,C盘空间越来越小怎么办有效解决方案
- 前三周学习Python的心得与感受
- Docker的镜像制作与整套项目一键打包部署
热门文章
- V-REP用户手册(翻译)(一)
- (6)理解事务处理、事务处理的隔离级别,和使用JDBC进行事务处理||抛弃框架,如何实现分层架构下JDBC事务的控制
- eureka使用总结
- MATLAB算法实战应用案例精讲-【元启发式算法】随机蛙跳跃算法(SFLA)(补充篇)(附Python代码实现)
- 赛尔号和赛尔机器人_探索赛尔号:赛尔机器人全身数据,你肯定不知道
- 最强蜗牛击败毁灭机器人_最强蜗牛恶魔形态怎么解锁 恶魔形态所有阶级详解[多图]...
- javaweb网上购物系统,jsp网页线上购物,mysql数据库(源码+报告)
- 林乐博士走进中国人民大学,讲述区块链的理解与实践
- Opencv图像几何变换
- 简易版Factorio开发问题记录