700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 说ueditor上传图片功能

说ueditor上传图片功能

时间:2018-10-13 06:29:45

相关推荐

说ueditor上传图片功能

php教程|php手册

thinkphp代码,代码示例,代码参考,php短信,数据库备份代码,令牌验证,去除代码中的空白和注释ueditor 上

php教程-php手册

说ueditor上传图片功能

借鉴了ueditor自带的php代码,和ot中的相关代码。

此代码已发布到我的csdn当中<?php

// +----------------------------------------------------------------------

// | UploaderController

// +----------------------------------------------------------------------

// | Copyright (c) AntDz All rights reserved.

// +----------------------------------------------------------------------

// | Author: antdz

// +----------------------------------------------------------------------

namespace Admin\Controller;

use Think\Controller;

@ini_set(upload_max_filesize, 20M);

qq申诉工具源码,ubuntu终端命令符,黑色爬虫吃蚜虫,去掉.php,南山seo宣传lzw

class UploaderController extends Controller {

public function index() {

$this -> display();

}

美食网源码免费,ubuntu终端分屏幕,tomcat一般用什么端口,儿童睡觉爬虫子,php扩展名是什么文件,阿里必应seolzw

/**

* 用于百度ueditor

* 其中UE_CONFIG在config文件中定义

*/

ipmsg java源码,vscode画画,ubuntu ded,搭建tomcat流媒体服务器,sqlite写并发,东营网页设计制作公司,贵阳服务器托管,ie8 svg 插件,前端框架集合网站,百家号爬虫,php 获取昨天日期,懒人seo,外贸php网站源码,爱情唯美网页模板,ok3w模板,jquery 页面验证,学生管理系统c语言代码,java小程序代码lzw

public function manager() {

date_default_timezone_set("Asia/Chongqing");

$CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(C(UE_CONFIG))), true);

$action = $_GET[action];

switch ($action) {

case config :

$result = $CONFIG;

break;

case listfile :

case listimage :

$result = $this -> lists($CONFIG, $action);

break;

/* 上传图片 */

case uploadimage :

/* 上传涂鸦 */

case uploadscrawl :

$config = array(maxSize => $CONIFG[imageMaxSize], ootPath => C(UPLOAD_PATH), savePath => images/, saveName => array(uniqid, \), exts => $CONIFG[imageAllowFiles], autoSub => true, subName => array(date, Ymd), );

$result = $this -> up($config);

break;

/* 上传视频 */

case uploadvideo :

$config = array(maxSize => $CONIFG[videoMaxSize], ootPath => C(UPLOAD_PATH), savePath => videos/, saveName => array(uniqid, \), exts => array(jpg, gif, png, jpeg, zip, doc, pdf), autoSub => true, subName => array(date, Ymd), );

$result = $this -> up($config);

break;

/* 上传文件 */

case uploadfile :

default :

$config = array(maxSize => $CONIFG[fileMaxSize], ootPath => C(UPLOAD_PATH), savePath => files/, saveName => array(uniqid, \), exts => $CONIFG[fileManagerAllowFilesarray], autoSub => true, subName => array(date, Ymd), );

$result = $this -> up($config);

break;

}

/* 输出结果 */

if (isset($_GET["callback"])) {

if (preg_match("/^[\w_]+$/", $_GET["callback"])) {

$this -> ajaxReturn($result, JSON);

} else {

$tmp = array(state => callback参数不合法);

$this -> ajaxReturn($tmp, JSON);

}

} else {

//echo $result;

$this -> ajaxReturn($result, JSON);

}

}

/**

* 用于百度编辑器上传功能

*/

public function up($config) {

//TODO:删除不删除?

@ini_set(upload_max_filesize, 20M);

$Picture = D(Picture);

$file_driver = C(PICTURE_UPLOAD_DRIVER);

$info = $Picture -> upload($_FILES, $config, C(PICTURE_UPLOAD_DRIVER), C("UPLOAD_{$file_driver}_CONFIG"));

if ($info) {

if ($info[upfile][url] == "") {

return array(url => __ROOT__ . $info[upfile][path], itle => htmlspecialchars($_POST[pictitle], ENT_QUOTES), original => $info[upfile][ ame], state => SUCCESS);

} else {

return array(url => $info[upfile][url], itle => htmlspecialchars($_POST[pictitle], ENT_QUOTES), original => $info[upfile][ ame], state => SUCCESS);

}

} else {

return array(state => $Picture -> getError());

//获取失败信息

}

}

/**

*百度编辑器列出本地服务器上传目录

*

*

**/

public function lists($config, $type) {

switch ($type) {

case listfile :

$allowFiles = $config[fileManagerAllowFiles];

$listSize = $config[fileManagerListSize];

$path = $config[fileManagerListPath];

break;

default :

$allowFiles = $config[imageManagerAllowFiles];

$listSize = $config[imageManagerListSize];

$path = $config[imageManagerListPath];

break;

}

$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 = DOC_ROOT . C(UPLOAD_PATH);

$files = $this -> getfiles($path, $allowFiles);

if (!count($files)) {

return array("state" => "no match file", "list" => array(), "start" => $start, "total" => count($files));

}

/* 获取指定范围的列表 */

$len = count($files);

for ($i = min($end, $len) - 1, $list = array(); $i = 0 && $i >= $start; $i--) {

$list[] = $files[$i];

}

$result = array("state" => "SUCCESS", "list" => $list, "start" => $start, "total" => count($files));

return $result;

}

/**

* 获取本地文件

*/

function getfiles($path, $allowFiles, &$files = array()) {

if (!is_dir($path)) {

exit(E1:path is wrong . $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;

}

/**

* 上传图片

* @author huajie

*/

public function uploadPicture() {

/* 返回标准数据 */

$return = array(status => 1, info => 上传成功, data => \);

/* 调用文件上传组件上传文件 */

$Picture = D(Picture);

$file_driver = C(PICTURE_UPLOAD_DRIVER);

$info = $Picture -> upload($_FILES, C(PICTURE_UPLOAD), C(PICTURE_UPLOAD_DRIVER), C("UPLOAD_{$file_driver}_CONFIG"));

//TODO:上传到远程服务器

/* 记录图片信息 */

if ($info) {

$return[status] = 1;

$return = array_merge($info[download], $return);

} else {

$return[status] = 0;

$return[info] = $Picture -> getError();

}

/* 返回JSON数据 */

$this -> ajaxReturn($return);

}

}

AD:真正免费,域名+虚机+企业邮箱=0元

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。