thinkphp3.2.3 ueditor1.4.3 圖片上傳操作,在線刪除上傳圖片功能。

最近弄一個圖片 上傳,可是用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;
        $upload->savePath = $this->getFullPath($config['pathFormat']); // 設置附件上傳(子)目錄
        $info = $upload->uploadOne($_FILES[$fieldName]);
        $rootpath = $this->rootpath;

        if (!$info) {
            $data = array("state" => $upload->getError(),);
        } else {
            $data = array(
                'state' => "SUCCESS",
                'url' => FileStorage::getPath($rootpath, $info['savepath'] . $info['savename']),
                'title' => $info['savename'],
                'original' => $info['name'],
                'type' => '.' . $info['ext'],
                'size' => $info['size'],
            );
            Image::water($data["url"], "./Public/" . MODULE_NAME . "/Images/logo.png");
        }
        return json_encode($data);
    }

    private function uploadBase64($config, $fieldName) {
        $data = array();
        $base64Data = $_POST[$fieldName];
        $img = base64_decode($base64Data);
        $path = $this->getFullPath($config['pathFormat']);
        if (strlen($img) > $config['maxSize']) {
            $data['states'] = 'too large';
            return json_encode($data);
        }
        $rootpath = $this->rootpath;
        //替換隨機字符串
        $imgname = uniqid() . '.png';
        $filename = $path . $imgname;
        if (FileStorage::put($rootpath, $filename, $img)) {
            $data = array(
                'state' => 'SUCCESS',
                'url' => FileStorage::getPath($rootpath, $filename),
                'title' => $imgname,
                'original' => 'scrawl.png',
                'type' => '.png',
                'size' => strlen($img),
            );
        } else {
            $data = array(
                'state' => 'cant write',
            );
        }
        return json_encode($data);
    }

    /**
     * 列出文件夾下所有文件,如果是目錄則向下
     */
    private function listFile($config) {
        $allowFiles = substr(str_replace(".", "|", join("", $config['allowFiles'])), 1);
        $size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $config['listSize'];
        $start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0;
        $end = $start + $size;
        $rootpath = $this->rootpath;
        $path = $config['path'];
        $files = FileStorage::listFile($rootpath, $path, $allowFiles);
        //return $files;
        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];
        }
        //倒序
        //for ($i = $end, $list = array(); $i < $len && $i < $end; $i++){
        //    $list[] = $files[$i];
        //}
        /* 返回數據 */
        $result = json_encode(array(
            "state" => "SUCCESS",
            "list" => $list,
            "start" => $start,
            "total" => count($files)
        ));
        return $result;
    }
    /**
     * 
     * Enter description here ...
     */
    private function saveRemote($config, $fieldName) {
        $list = array();
        if (isset($_POST[$fieldName])) {
            $source = $_POST[$fieldName];
        } else {
            $source = $_GET[$fieldName];
        }
        foreach ($source as $imgUrl) {
            $upload = new \Think\Upload();
            $imgUrl = htmlspecialchars($imgUrl);
            $imgUrl = str_replace("&amp;", "&", $imgUrl);
            //http開頭驗證
            if (strpos($imgUrl, "http") !== 0) {
                $data = array('state' => '不是http鏈接');
                return json_encode($data);
            }
            //格式驗證(擴展名驗證和Content-Type驗證)
            $fileType = strtolower(strrchr($imgUrl, '.'));
            if (!in_array($fileType, $config['allowFiles']) || stristr($heads['Content-Type'], "image")) {
                $data = array("state" => "錯誤文件格式");
                return json_encode($data);
            }
            //打開輸出緩衝區並獲取遠程圖片
            ob_start();
            $context = stream_context_create(
                    array('http' => array(
                            'follow_location' => false // don't follow redirects
                        ))
            );
            readfile($imgUrl, false, $context);
            $img = ob_get_contents();
            ob_end_clean();
            preg_match("/[\/]([^\/]*)[\.]?[^\.\/]*$/", $imgUrl, $m);
            $path = $this->getFullPath($config['pathFormat']);
            if (strlen($img) > $config['maxSize']) {
                $data['states'] = 'too large';
                return json_encode($data);
            }
            $rootpath = $this->rootpath;
            $imgname = uniqid() . '.png';
            $filename = $path . $imgname;
            $oriName = $m ? $m[1] : "";
            if (FileStorage::put($rootpath, $filename, $img)) {
                array_push($list, array(
                    "state" => 'SUCCESS',
                    "url" => \vin\FileStorage::getPath($rootpath, $filename),
                    "size" => strlen($img),
                    "title" => $imgname,
                    "original" => $oriName,
                    "source" => htmlspecialchars($imgUrl)
                ));
            } else {
                array_push($list, array('state' => '文件寫入失敗'));
            }
        }
        /* 返回抓取數據 */
        return json_encode(array(
            'state' => count($list) ? 'SUCCESS' : 'ERROR',
            'list' => $list
        ));
    }
    /**
     * 規則替換命名文件
     * @param $path
     * @return string
     */
    private function getFullPath($path) {
        //替換日期事件
        $t = time();
        $d = explode('-', date("Y-y-m-d-H-i-s"));
        $format = $path;
        $format = str_replace("{yyyy}", $d[0], $format);
        $format = str_replace("{yy}", $d[1], $format);
        $format = str_replace("{mm}", $d[2], $format);
        $format = str_replace("{dd}", $d[3], $format);
        $format = str_replace("{hh}", $d[4], $format);
        $format = str_replace("{ii}", $d[5], $format);
        $format = str_replace("{ss}", $d[6], $format);
        $format = str_replace("{uid}", $this->uid, $format);
        return $format;
    }
    private function format_exts($exts) {
        $data = array();
        foreach ($exts as $key => $value) {
            $data[] = ltrim($value, '.');
        }
        return $data;
    }
}
PublicClass/FileStorage/Dirver/Sae.class.php
<?php
/**
 * 
 * @author Nintendov
 */
namespace PublicClass\FileStorage\Driver;
use PublicClass\FileStorage;
class Sae extends FileStorage{
    private $st;

    private $error;

    public function __construct(){
        if(!function_exists('memcache_init')){
              header('Content-Type:text/html;charset=utf-8');
              exit('請在SAE平臺上運行代碼。');
        }

        $this->st = new \SaeStorage();

    }

    public function getFilename($filename){
        if(strpos($filename, __ROOT__)) $filename = str_replace(__ROOT__, '', $filename,1);
        return $filename;
    }

    /**
     * 寫文件
     * @param 文件名
     * @param 文件內容
     * @param 限制尺寸 默認不限制
     * @param 是否覆蓋 默認是
     */
    public function put($rootpath,$filename, $content,$maxSize=-1, $cover = TRUE){
        $rootpath = trim($rootpath,'/');

        $filename = $this->getFilename($filename);

        if($maxSize!=-1) if(strlen($content)>$maxSize) return '文件大小超過限制';

        if($cover){
            if($this->st->fileExists($rootpath,$filename)) $this->st->delete($rootpath,$filename);
        }

        return $this->st->write($rootpath,$filename,$content);
    }


    public function listFile($rootpath,$path , $allowFiles='all'){
        $rootpath = trim($rootpath,'/');
        $path = trim($path,'/');
        return $this->getList($rootpath, $path,$allowFiles);
    }
    /**
     * 遍歷獲取目錄下的指定類型的文件
     * @param $path
     * @param array $files
     * @return array
     */
    public function getList($domain, $path, $allowFiles='all' , &$list=array()){
        $allowFiles = 'all';
        $handle = $this->st->getListByPath($domain , $path , 1000);

        if($handle['dirNum'] > 0){
            foreach ($handle['dirs'] as $dir) {
                $dirname = trim($dir['fullName'],'/');
                $this->getList($domain, $dirname,$allowFiles, $list);
            }
        }

        foreach ($handle['files'] as $file){
            if($allowFiles!='all'){
                if (preg_match("/\.(".$allowFiles.")$/i", $file['fullName'])) {
                    $list[] = array(
                        'url'=> $this->st->getUrl($domain,$file['fullName']),
                        'mtime'=> $file['uploadTime']
                    );
                }
            }else{
                $list[] = array(
                    'url'=> $this->st->getUrl($domain,$file['fullName']),
                    'mtime'=> $file['uploadTime']
                );
            }
        }
        return $list;
    }

    /**
     * 得到路徑
     */
    public function getPath($rootpath,$path){
        $rootpath = trim($rootpath,'/');
        $url = $this->st->getUrl($rootpath,$path);
        return $url;
    }
}
PublicClass/FileStorage/Dirver/File.class.php
<?php
/**
 * 本地文件處理類
 * @author Nintendov
 */
namespace PublicClass\FileStorage\Driver;
use PublicClass\FileStorage;
class File extends FileStorage{
    /**
     * 本地寫文件
     */
    public function put($rootpath,$filename, $content,$maxSize=-1, $cover = TRUE){
        $filename = '.'.$rootpath.$filename;
        if($maxSize!=-1){
            if(strlen($content>$maxSize)){
                return '文件大小超過限制';
            }
        }
        $dir         =  dirname($filename);
        if(!is_dir($dir))
            mkdir($dir,0755,true);
        if(false === file_put_contents($filename,$content)){
            E(L('_STORAGE_WRITE_ERROR_').':'.$filename);
        }else{
            $this->contents[$filename]=$content;
            return true;
        }
    }
    /**
     * 遍歷獲取目錄下的指定類型的文件
     * @param $path
     * @param array $files
     * @return array
     */

    public function listFile($rootpath, $path ,$allowFiles='all'){
        $path = $_SERVER['DOCUMENT_ROOT'].__ROOT__.$rootpath.$path;
        return $this->getList($path, $allowFiles);
    }

    public function getList($path ,$allowFiles='all' , &$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->getList($path2, $allowFiles, $files);
                } else {
                    if($allowFiles!='all'){
                        if (preg_match("/\.(".$allowFiles.")$/i", $file)) {
                            $files[] = array(
                                'url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])),
                                'mtime'=> filemtime($path2)
                            );
                        }
                    }else{
                        $files[] = array(
                                'url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])),
                                'mtime'=> filemtime($path2)
                        );
                    }
                }
            }
        }
        return $files;
    }
    /**
     * 得到路徑
     */
    public function getPath($rootpath,$path){
        $path = __ROOT__.$rootpath.$path;
        return $path;
    }
}

幾個類已經好了,現在修改config文件。

return array(
    //'配置項'=>'配置值'
    'UEDITOR_CONFIG_PATH'=>MODULE_PATH.'Conf/ueditor.json',//配置信息
    'UEDITOR_CONFIG_IMG_DEL_URL'=>"/".MODULE_NAME.".php/UploadManager/ajaxImgDel",//要刪除圖片的URL地址
);
/* 前後端通信相關的配置,註釋只允許使用多行方式 */
{
    /* 上傳圖片配置項 */
    "imageActionName": "uploadimage", /* 執行上傳圖片的action名稱 */
    "imageFieldName": "upfile", /* 提交的圖片表單名稱 */
    "imageMaxSize": 12048000, /* 上傳大小限制,單位B */
    "imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上傳圖片格式顯示 */
    "imageCompressEnable": true, /* 是否壓縮圖片,默認是true */
    "imageCompressBorder": 1600, /* 圖片壓縮最長邊限制 */
    "imageInsertAlign": "none", /* 插入的圖片浮動方式 */
    "imageUrlPrefix": "", /* 圖片訪問路徑前綴 */
    "imagePathFormat": **"/ueditor/image/{yyyy}{mm}{dd}/"**, /* 上傳保存路徑,可以自定義保存路徑 */
   /* {uid} 會替換成當前用戶id*/
   /* {filename} 會替換成原文件名,配置這項需要注意中文亂碼問題 */
   /* {rand:6} 會替換成隨機數,後面的數字是隨機數的位數 */
   /* {time} 會替換成時間戳 */
   /* {yyyy} 會替換成四位年份 */
   /* {yy} 會替換成兩位年份 */
   /* {mm} 會替換成兩位月份 */
   /* {dd} 會替換成兩位日期 */
   /* {hh} 會替換成兩位小時 */
   /* {ii} 會替換成兩位分鐘 */
   /* {ss} 會替換成兩位秒 */
   /* 非法字符 \ : * ? " < > | */
   /* 塗鴉圖片上傳配置項 */
    "scrawlActionName": "uploadscrawl", /* 執行上傳塗鴉的action名稱 */
    "scrawlFieldName": "upfile", /* 提交的圖片表單名稱 */
    **"scrawlPathFormat": "/ueditor/image/{yyyy}{mm}{dd}/"**, /* 上傳保存路徑,可以自定義保存路徑 */
    "scrawlMaxSize": 2048000, /* 上傳大小限制,單位B */
    "scrawlUrlPrefix": "", /* 圖片訪問路徑前綴 */
    "scrawlInsertAlign": "none",

    /* 截圖工具上傳 */
    "snapscreenActionName": "uploadimage", /* 執行上傳截圖的action名稱 */
    "snapscreenPathFormat": "/ueditor/image/{yyyy}{mm}{dd}/", /* 上傳保存路徑,可以自定義保存路徑 */
    "snapscreenUrlPrefix": "", /* 圖片訪問路徑前綴 */
    "snapscreenInsertAlign": "none", /* 插入的圖片浮動方式 */

    /* 抓取遠程圖片配置 */
    "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
    "catcherActionName": "catchimage", /* 執行抓取遠程圖片的action名稱 */
    "catcherFieldName": "source", /* 提交的圖片列表表單名稱 */
    "catcherPathFormat": "/ueditor/image/{yyyy}{mm}{dd}/", /* 上傳保存路徑,可以自定義保存路徑 */
    "catcherUrlPrefix": "", /* 圖片訪問路徑前綴 */
    "catcherMaxSize": 2048000, /* 上傳大小限制,單位B */
    "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取圖片格式顯示 */

    /* 上傳視頻配置 */
    "videoActionName": "uploadvideo", /* 執行上傳視頻的action名稱 */
    "videoFieldName": "upfile", /* 提交的視頻表單名稱 */
    **"videoPathFormat": "/ueditor/video/{yyyy}{mm}{dd}/"**, /* 上傳保存路徑,可以自定義保存路徑 */
    "videoUrlPrefix": "", /* 視頻訪問路徑前綴 */
    "videoMaxSize": 102400000, /* 上傳大小限制,單位B,默認100MB */
    "videoAllowFiles": [
        ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
        ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], /* 上傳視頻格式顯示 */

    /* 上傳文件配置 */
    "fileActionName": "uploadfile", /* controller裏,執行上傳視頻的action名稱 */
    "fileFieldName": "upfile", /* 提交的文件表單名稱 */
    **"filePathFormat": "/ueditor/file/{yyyy}{mm}{dd}/"**, /* 上傳保存路徑,可以自定義保存路徑 */
    "fileUrlPrefix": "", /* 文件訪問路徑前綴 */
    "fileMaxSize": 20480000, /* 上傳大小限制,單位B,默認20MB */
    "fileAllowFiles": [
        ".png", ".jpg", ".jpeg", ".gif", ".bmp",
        ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
        ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
        ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
        ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
    ], /* 上傳文件格式顯示 */

    /* 列出指定目錄下的圖片 */
    "imageManagerActionName": "listimage", /* 執行圖片管理的action名稱 */
    "imageManagerListPath": "/ueditor/image/", /* 指定要列出圖片的目錄 */
    "imageManagerListSize": 20, /* 每次列出文件數量 */
    "imageManagerUrlPrefix": "", /* 圖片訪問路徑前綴 */
    "imageManagerInsertAlign": "none", /* 插入的圖片浮動方式 */
    "imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件類型 */

        /**********liaohb************/
    /*刪除圖片操作*/
    "imageDelUrl":"/uploadify/ajaxDel",/*刪除圖片管理操作的URL地址*/

    /* 列出指定目錄下的文件 */
    "fileManagerActionName": "listfile", /* 執行文件管理的action名稱 */
    **"fileManagerListPath": "/ueditor/file/"**, /* 指定要列出文件的目錄 */
    "fileManagerUrlPrefix": "", /* 文件訪問路徑前綴 */
    "fileManagerListSize": 20, /* 每次列出文件數量 */
    "fileManagerAllowFiles": [
        ".png", ".jpg", ".jpeg", ".gif", ".bmp",
        ".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
        ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
        ".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
        ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
    ] /* 列出的文件類型 */
}

添加一個上傳圖片控制器,要在項目根下添加一個文件夾 /Uploads,上傳的圖片就會存放到這裏去。

UploadManagerController
<?php
namespace BlogAdmin\Controller;
class UploadManagerController extends \Think\Controller {
    public function ajaxImgDel() {
        $filePath = "." . I("path");
        if (file_exists($filePath)) {
            $data = array();
            if (unlink($filePath)) {
                $data["state"] = 'success';
                $data['message'] = '刪除成功';
            } else {
                $data["state"] = 'failure';
                $data['message'] = '刪除失敗,請檢查權限~~' . $filePath;
            }
            echo json_encode($data);
        }
    }
    public function ajaxUpload() {
        C('SHOW_PAGE_TRACE', false);//加上這名話,要不能在開始頁面追
        $data = new \PublicClass\Ueditor();
        echo $data->output();
    }
}

界面使用,js的路徑引用有好多種;

 <script type="text/javascript">
   var uploadURL = "__MODULE__/UploadManager/ajaxUpload";
   window.UEDITOR_HOME_URL = "__PUBLIC__/ueditor/";
   window.onload = function () {
       window.UEDITOR_CONFIG.initialFrameWidth = "100%";  
      window.UEDITOR_CONFIG.initialFrameHeight = 150;  
      window.UEDITOR_CONFIG.serverUrl = uploadURL;//"__CONTROLLER__/upload";
     UE.getEditor('content');
   }
   </script>
   <script type="text/javascript" src="{$Think.const.BLOGADMIN_UEDITOR}/ueditor.config.js"></script>
   <script type="text/javascript" src="{$Think.const.BLOGADMIN_UEDITOR}/ueditor.all.js"></script>

這裏寫圖片描述

—————————————————–

刪除上傳的圖片。
要修改幾個地方:
Public/ueditor/dialogs/image/image.js:

/**********liaohb************/
/*添加刪除操作*/
del = document.createElement('a');    
del.innerHTML = '刪除';
domUtils.addClass(del, 'del');
var delid='imagelist_'+i;
del.setAttribute('id',delid);
del.setAttribute('href','javascript:;');
del.setAttribute('onclick','uedel("'+list[i].url+'","'+delid+'")');
item.appendChild(del);                    

這裏寫圖片描述
Public/ueditor/dialogs/image/image.html

 <script>
/**********liaohb************/
//新增在線管理刪除圖片
function uedel(path, id){
  if(confirm('您確定要刪除它嗎?刪除後不可恢復!')){                     
      var url = editor.getOpt('imageDelUrl');   
      $.get(url,{'path':path},function(data){
          if (data.state == 'success') {
              alert(data.message);
              $("#"+id).parent("li").remove();                   
          }else{
              alert(data.message);
          }
      },'json');            
    }        
}
</script>

還要在image.css文件底部加上一些樣式

/* 新增在線管理刪除圖片樣式*/
#online li a.del {      
    width: auto;    
    position: absolute;
    top: 0;
    right: 0;
    color:#F00;
    background-color:#DDDDDD;
    opacity:0.8;
    filter:alpha(80);
    border: 0;   
    z-index:3;
    text-align:right;
    text-decoration:none;    
}

這裏寫圖片描述

都弄好了,可以先看看效果
這裏寫圖片描述
點擊確定,左邊圖到的圖片就不見了。
這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章