[umeditor] 多圖片一次上傳功能

本人一直喜歡精簡的大代碼,ueditor  感受有點大。umeditor是他的精簡版,全部就用umeditor了.javascript

umeditor 和ueditor 我看了下代碼都只提供了單圖片上傳。php

imageUp.php:html

把兩處修改了.java

<?php
    header("Content-Type:text/html;charset=utf-8");
    error_reporting( E_ERROR | E_WARNING );
    date_default_timezone_set("Asia/chongqing");
    include "Uploader_ext.class.php";  
    //上傳配置
    $config = array(
        "savePath" => "upload/" ,             //存儲文件夾
        "maxSize" => 2040 ,                   //容許的文件最大尺寸,單位KB
        "allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" )  //容許的文件格式
    );
    //上傳文件目錄
    $Path = "upload/";

    //背景保存在臨時目錄中
    $config[ "savePath" ] = $Path;
    $up = new Uploader_ext( "upfile" , $config );
    $type = $_REQUEST['type'];
    $callback=$_GET['callback'];

    $info = $up->getFileInfo();
    /**
     * 返回數據
     */
    if($callback) {
        echo '<script>'.$callback.'('.json_encode($info).')</script>';
    } else {
        echo json_encode($info);
    }

最主要的上傳代碼:json

private function upFile($base64)
    { 
        // 處理base64上傳
        /**
         * if ( "base64" == $base64 ) {
         * $content = $_POST[ $this->fileField ];
         * $this->base64ToImage( $content );
         * return;
         * }
         */
        // 處理普通上傳
        $file = $this -> file = $_FILES[ $this -> fileField ];

        if (!$file)
        {
            $this -> stateInfo = $this -> getStateInfo('POST');
            return;
        } 

        $this -> all_data = array();
        
        $_count = count($_FILES[ $this -> fileField ]['name']);
        for($i = 0;$i < $_count;$i++)
        {
            if ($this ->file[ 'error' ][$i] !=0)
            {
                $this -> stateInfo = $this -> getStateInfo($file[ 'error' ]);
                return;
            } 

            if (!is_uploaded_file($file[ 'tmp_name' ][$i]))
            {
                $this -> stateInfo = $this -> getStateInfo("UNKNOWN");
                return;
            } 

            $this -> oriName = $file[ 'name' ][$i];

            $this -> fileSize = $file[ 'size' ][$i];

            $this -> fileType = $this -> getFileExt($file[ 'name' ][$i]);

            if (!$this -> checkSize())
            {
                $this -> stateInfo = $this -> getStateInfo("SIZE");
                return;
            } 
            
            if (!$this -> checkType($this -> fileType))
            {
                $this -> stateInfo = $this -> getStateInfo("TYPE");
                return;
            } 

            $folder = $this -> getFolder();

            if ($folder === false)
            {
                $this -> stateInfo = $this -> getStateInfo("DIR_ERROR");
                return;
            } 

            $this -> fullName = $folder . '/' . $this -> getName($this -> fileType);

            if ($this -> stateInfo == $this -> stateMap[ 0 ])
            {
                if (!move_uploaded_file($file[ "tmp_name" ][$i] , $this -> fullName))
                {
                    $this -> stateInfo = $this -> getStateInfo("MOVE");
                } 
            } 

            $this -> all_data[] = array("originalName" => $file[ 'name' ][$i] ,
                "name" => $this -> fileName ,
                "url" => $this -> fullName ,
                "size" => $file[ 'size' ][$i] ,
                "type" => $this -> fileType ,
                "state" => $this -> stateInfo
                );
        } 
    }

js代碼中處理:ide

主要調用:Base.callback(me.editor, me.dialog, item.url, item.state);post

$.each(json,function(idx,item){ 
					//alert("value:"+item.url); 
					Base.callback(me.editor, me.dialog, item.url, item.state);
				});
uploadTpl: '<div class="edui-image-upload%%">' +
            '<span class="edui-image-icon"></span>' +
            '<form class="edui-image-form" method="post" enctype="multipart/form-data" target="up">' +
            '<input style=\"filter: alpha(opacity=0);\" class="edui-image-file" type="file" hidefocus name="upfile[]"  multiple="multiple" accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"/>' +
            '</form>' +

            '</div>',
相關文章
相關標籤/搜索