thinkphp3.2.3 ueditor1.4.3 图片上传操作,在线删除上传图片功能。

本文介绍了如何在ThinkPHP3.2.3框架下结合UEditor1.4.3实现图片上传功能,包括配置ueditor-thinkphp插件、创建上传图片控制器以及设置上传路径。同时,文章详细讲解了在线删除已上传图片的步骤,涉及image.js、image.html和image.css的修改。通过这些操作,可以确保图片上传并存储在项目指定目录,且能成功删除选择的图片。
摘要由CSDN通过智能技术生成

最近弄一个图片 上传,可是用ueditor 自带的上传,如果不配置的话,上传的目录不在自己的项目中。

在网上找了好多,可是都是底版本的,新版本的还真是找到了一个,ueditor-thinkphp 这个打开可以去下载,

把里面的几个类弄出来,
这里写图片描述

PublicClass/FileStorage.class.php
<?php
/**
 * 文件管理类
 * @author Nintendov
 */
namespace PublicClass;
class FileStorage{
    /**
     * 操作句柄
     * @var string
     * @access protected
     */
    static protected $handler    ;
    /**
     * 连接分布式文件系统
     * @access public
     * @param string $type 文件类型
     * @param array $options  配置数组
     * @return void
     */
    static public function connect($type='File',$options=array()) {
        $class  =   'PublicClass\\FileStorage\\Driver\\'.ucwords($type);
        self::$handler = new $class($options);
    }
        static public function __callstatic($method,$args){
        //调用缓存驱动的方法
        if(method_exists(self::$handler, $method)){
           return call_user_func_array(array(self::$handler,$method), $args);
        }
    }
}
PublicClass/Ueditor.class.php
<?php
namespace PublicClass;
/**
 * Ueditor插件
 * @author Nintendov
 */
class Ueditor {
    
    //public $uid;//要操作的用户id 如有登录需要则去掉注释
    private $output; //要输出的数据
    private $st;
    private $rootpath = '/Uploads';
    public function __construct($uid = '') {
    
        //uid 为空则导入当前会话uid
        //if(''===$uid) $this->uid = session('uid');
        FileStorage::connect(STORAGE_TYPE);
        //导入设置
        $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(C("UEDITOR_CONFIG_PATH"))), true);

        $CONFIG["imageDelUrl"] =C("UEDITOR_CONFIG_IMG_DEL_URL");
                $action = htmlspecialchars($_GET['action']);

        switch ($action) {
            case 'config':
                $result = json_encode($CONFIG);
                break;
            case 'uploadimage':
                $config = array(
                    "pathFormat" => $CONFIG['imagePathFormat'],
                    "maxSize" => $CONFIG['imageMaxSize'],
                    "allowFiles" => $CONFIG['imageAllowFiles']
                );
                $fieldName = $CONFIG['imageFieldName'];
                $result = $this->uploadFile($config, $fieldName);
                break;
            case 'uploadscrawl':
                $config = array(
                    "pathFormat" => $CONFIG['scrawlPathFormat'],
                    "maxSize" => $CONFIG['scrawlMaxSize'],
                    "allowFiles" => $CONFIG['scrawlAllowFiles'],
                    "oriName" => "scrawl.png"
                );
                $fieldName = $CONFIG['scrawlFieldName'];
                $result = $this->uploadBase64($config, $fieldName);
                break;
            case 'uploadvideo':
                $config = array(
                    "pathFormat" => $CONFIG['videoPathFormat'],
                    "maxSize" => $CONFIG['videoMaxSize'],
                    "allowFiles" => $CONFIG['videoAllowFiles']
                );
                $fieldName = $CONFIG['videoFieldName'];
                $result = $this->uploadFile($config, $fieldName);
                break;
            case 'uploadfile':
                // default:
                $config = array(
                    "pathFormat" => $CONFIG['filePathFormat'],
                    "maxSize" => $CONFIG['fileMaxSize'],
                    "allowFiles" => $CONFIG['fileAllowFiles']
                );
                $fieldName = $CONFIG['fileFieldName'];
                $result = $this->uploadFile($config, $fieldName);
                break;
            case 'listfile':
                $config = array(
                    'allowFiles' => $CONFIG['fileManagerAllowFiles'],
                    'listSize' => $CONFIG['fileManagerListSize'],
                    'path' => $CONFIG['fileManagerListPath'],
                );
                $result = $this->listFile($config);
                break;
            case 'listimage':
                $config = array(
                    'allowFiles' => $CONFIG['imageManagerAllowFiles'],
                    'listSize' => $CONFIG['imageManagerListSize'],
                    'path' => $CONFIG['imageManagerListPath'],
                );
                $result = $this->listFile($config);
                break;
            case 'catchimage':
                $config = array(
                    "pathFormat" => $CONFIG['catcherPathFormat'],
                    "maxSize" => $CONFIG['catcherMaxSize'],
                    "allowFiles" => $CONFIG['catcherAllowFiles'],
                    "oriName" => "remote.png"
                );
                $fieldName = $CONFIG['catcherFieldName'];
                $result = $this->saveRemote($config, $fieldName);
                break;
            default:
                $result = json_encode(array(
                    'state' => 'wrong require'
                ));
                break;
        }
        if (isset($_GET["callback"])) {
            if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
                $this->output = htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
            } else {
                $this->output = json_encode(array(
                    'state' => 'callback参数不合法'
                ));
            }
        } else {
            $this->output = $result;
        }
    }
    /**
     * 
     * 输出结果
     * @param data 数组数据
     * @return 组合后json格式的结果
     */
    public function output() {
    
        return $this->output;
    }
    /**
     * 上传文件方法
     */
    private function uploadFile($config, $fieldName) {
    

        $upload = new \Think\Upload();
        $upload->maxSize = $config['maxSize']; // 设置附件上传大小
        $upload->exts = $this->format_exts($config['allowFiles']); // 设置附件上传类型
        $upload->rootPath = '.' . $this->rootpath; // 设置附件上传根目录
        $upload->autoSub = false;
        $uploa
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值