JQuery上傳外掛程式Uploadify

來源:互聯網
上載者:User

標籤:

一:官網

http://www.uploadify.com/

二:引用

<link href="plug-in/uploadify3.2.1/uploadify.css" rel="stylesheet" />
<script type="text/javascript" src="plug-in/uploadify3.2.1/jquery.uploadify.min.js"></script>

三:例子

(1)前台頁面

<tr>        <td align="right">            <label class="Validform_label"> 主題圖: </label>        </td>        <td class="value">             <input id="subjectMap" name="subjectMap" type="hidden" datatype="*" />             <table>                <tr>                    <td>                        <input type="file" name="upload_org_code" id="upload_org_code"/>                    </td>                    <td>                       <img  id="upload_org_code_img" src="" width="216" height="135">                       <a  id="del" style="display: none;" href="#" onclick="del()">刪除</a>                    </td>                </tr>             </table>             <span class="Validform_checktip">建議尺寸:720*360</span>        </td></tr>

 (2)上傳JS

setTimeout(function(){         $("#upload_org_code").uploadify({                    ‘height‘        : 27,                    ‘width‘         : 80,                     ‘buttonText‘    : ‘圖片上傳‘,                    ‘swf‘           : ‘plug-in/uploadify3.2.1/uploadify.swf‘,                    ‘uploader‘      : ‘rouletteController.do?objUpload‘,                    ‘auto‘          : true,                    ‘multi‘         : false,                    ‘removeCompleted‘:true,                    ‘removeTimeout‘ : 1,                    ‘cancelImg‘     : ‘plug-in/uploadify3.2.1/uploadify-cancel.png‘,                    ‘fileTypeExts‘  : ‘*.jpg;*.jpge;*.gif;*.png‘,                    ‘fileSizeLimit‘ : ‘2MB‘,                    ‘onUploadSuccess‘:function(file,data,response){                        var json = eval(‘(‘ + data + ‘)‘);                         var url=json.attributes.visiturl+json.attributes.fileName;                        $("#upload_org_code_img").attr("src",url);                         $("#subjectMap").val(json.attributes.fileName);                         $("#del").attr("style","display: block;");                    },                    //加上此句會重寫onSelectError方法【需要重寫的事件】                    ‘overrideEvents‘: [‘onSelectError‘, ‘onDialogClose‘],                    //返回一個錯誤,選擇檔案的時候觸發                    ‘onSelectError‘:function(file, errorCode, errorMsg){                        switch(errorCode) {                            case -110:                                alert("檔案 ["+file.name+"] 大小超出系統限制的" +                     jQuery(‘#upload_org_code‘).uploadify(‘settings‘, ‘fileSizeLimit‘) + "大小!");                                break;                            case -120:                                alert("檔案 ["+file.name+"] 大小異常!");                                break;                            case -130:                                alert("檔案 ["+file.name+"] 類型不正確!");                                break;                        }                    },                });           },10)  

(3)上傳後台代碼

/****     * 圖片上傳     **/    @RequestMapping(params = "objUpload")    @ResponseBody    public AjaxJson objUpload(HttpServletRequest request) throws Exception {        AjaxJson j = new AjaxJson();        Map<String, Object> attributes = new HashMap<String, Object>();        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();        String tomcaturl = PropertiesConfig.getStringConfig("tomcaturl");        String roulette_sub_url = PropertiesConfig.getStringConfig("roulette_sub_url");        String visiturl = PropertiesConfig.getStringConfig("visiturl");        // 建立檔案夾        File file = new File(tomcaturl+roulette_sub_url);        if (!file.exists()) {            file.mkdirs();        }        String fileName = null;        //String path = null;        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {            // 上傳檔案名稱            MultipartFile mf = entity.getValue();            fileName = mf.getOriginalFilename();            String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1)                    .toLowerCase();            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");            String newFileName = "roulette_" + df.format(new Date()) +"_bak"+ "." + fileExt;            File uploadFile = new File(tomcaturl+roulette_sub_url+newFileName);            try {                FileCopyUtils.copy(mf.getBytes(), uploadFile);                fileName = roulette_sub_url+newFileName;            } catch (IOException e) {                e.printStackTrace();            }        }        attributes.put("visiturl", visiturl);        attributes.put("fileName", fileName);        j.setAttributes(attributes);        return j;    }
View Code

 

JQuery上傳外掛程式Uploadify

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.