一:官网

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;
    }

JQuery上传插件Uploadify的更多相关文章

  1. JQuery上传插件uploadify优化

    旧版的uploadify是基于flash上传的,但是总有那么些问题,让我们用的不是很舒服.今天主要分享下在项目中用uploadify遇到的一些问题,以及优化处理 官方下载 官方文档 官方演示 下面是官 ...

  2. jquery上传插件uploadify 报错http error 302 解决方法之一

    前段时间用到jquery上传插件uploadify时,始终出现系统报出 http error 302 的错误. 网上大量搜集信息,基本上都是说session值丢失的问题,根据网友提供的解决方案进行修改 ...

  3. 【转】JQuery上传插件Uploadify使用详解及错误处理

    转自:http://www.jb51.net/article/43498.htm 关于JQuery上传插件Uploadify使用详解网上一大把,基本上内容都一样.我根据网上的步骤配置完成后,会报一些错 ...

  4. JQuery上传插件Uploadify使用详解

    本文转载http://www.cnblogs.com/oec2003/archive/2010/01/06/1640027.html Uploadify是JQuery的一个上传插件,实现的效果非常不错 ...

  5. (转)JQuery上传插件Uploadify使用详解

    原文地址:http://www.cnblogs.com/oec2003/archive/2010/01/06/1640027.html Uploadify是JQuery的一个上传插件,实现的效果非常不 ...

  6. jQuery上传插件Uploadify使用帮助

    Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示.它的功能特色总结如下: 支持单文件或多文件上传,可控制并发上传的文件数 在服务器端支持各种语言与之配合使用,诸如PHP, ...

  7. JQuery上传插件Uploadify使用详解 asp.net版

    先来一个实例 Uploadify插件是JQuery的一个文件支持多文件上传的上传插件,ajax异步上传,实现的效果非常不错,带进度显示.不过官方提供的实例时php版本的,本文将详细介绍Uploadif ...

  8. 文件上传利器JQuery上传插件Uploadify

    在做日常项目中,经常在后台需要上传图片等资源文件,之前使用过几次这个组件,感觉非常好用 ,但是每次使用的时候都是需要经过一番查阅,所以还不如记住在这里,以后使用的时候就翻翻. 他的官方网站如下:htt ...

  9. jQuery上传插件Uploadify 3.2在.NET下的详细例子

    项目中要使用Uploadify 3.2来实现图片上传并生成缩略通的功能,特此记下来,以供各位参考! Uploadify下载地址:http://www.uploadify.com/download/ 下 ...

  10. JQuery上传插件Uploadify详解及其中文按钮解决方案 .

    Uploadify有一个参数是 buttonText 这个无论你怎么改都不支持中文,因为插件在js里用了一个转码方法把这个参数的值转过码了,解码的地方在那个swf文件里,看不到代码,所以这条路不行. ...

随机推荐

  1. [置顶] mysql中的set和enum类型的用法和区别

    mysql中的enum和set其实都是string类型的而且只能在指定的集合里取值,  不同的是set可以取多个值,enum只能取一个值.   CREATE TABLE `20121101_t` ( ...

  2. CSS3最简洁的轮播图

    <!DOCTYPE html> <html> <head> <title>CSS3最简洁的轮播图</title> <style> ...

  3. 读FCL源码系列之List<T>---让你知其所以然---内含疑问求大神指点

    序言 在.NET开发中,List<T>是我们经常用到的类型.前段时间看到其他部门小伙伴讨论“两个List(10W个元素)集合求并集,list1.Where(p=>list2.Cont ...

  4. echarts 折线柱形上方显示自定义格式数据

    series:[ { name: '成单率', type: 'line', data: valueArr2, itemStyle: { normal: { label: { show:true, po ...

  5. 关于.net的一些基础知识(二)

    索引器是什么?有什么作用?索引器允许类的实例以访问数组的形式来访问对象里面的属性.如我们经常可以看到类似于dr[“name”]=”test”,或者说以config[“connectString”]来获 ...

  6. hadoop备记

    Hadoop 的优势 Hadoop 是 一 个 能 够 让 用 户 轻 松 架 构 和 使 用 的 分 布 式 计 算 平 台. 用 户 可 以 轻 松 地 在Hadoop 上开发执行处理海量数据的应 ...

  7. [转]Reducing script compile time or a better workflow to reduce excessive recompiling

    http://forum.unity3d.com/threads/148078-Reducing-script-compile-time-or-a-better-workflow-to-reduce- ...

  8. ubuntu14.04源代码安装postgresql 9.1

    项目须要使用gisgraphy,怎奈gisgraphy3.0仅仅支持postgis1.5.因此仅仅能安装老版本号的posgresql和postgis了.从postgis的support matrix图 ...

  9. mysql 索引优化

    http://blog.jobbole.com/87107/ http://www.phpben.com/?post=74 http://blogread.cn/it/article/4088?f=s ...

  10. (转载)Ant教程

    ant教程(一) 写在所有之前 为了减少阅读的厌烦,我会使用尽量少的文字,尽量明白的表达我的意思,尽我所能吧.作为一个学习者,在我的文章中会存在各种问题,希望热心人指正.目录大概是这样 ant教程 ( ...