easyUI + swfupload 多附件上传功能,—少爵

选择文件.png上传.png上传界面 1.png

有图有真相 
这是少爵利用空余时间写的 easyui + swfupload 多文件上传的页面效果.

是个半成品 .任然有些问题 .有些文件上传成功却 0%. 有些文件上传错误 却 100%

当文件无后缀时. 上传却是不行.停止功能暂时不能用.取消所有可以使用. 

不允许选择存在于上传队列中的文件继续上传. 会弹出提示 .文件超大小.会提示 .


后台函数如下:

 1 public void UPLOADFILED() {
 2         Date dt = new Date(System.currentTimeMillis());
 3         SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
 4         String fileName = sdf.format(dt);
 5         int index = getUploadFileName().lastIndexOf(".");
 6         //得到文件扩展名
 7         String extendName = getUploadFileName().substring(index);
 8         String path = getRootPath()+"up\\";
 9         //String sessionId = getRequest().getSession().getId();
10         String filename = fileName + extendName;
11         Json j = uploadFile(filename, path, 200 * 1024 *1024, true);
12         try {
13             String json = JSON.toJSONStringWithDateFormat(j,"yyyy-MM-dd");
14             ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
15             ServletActionContext.getResponse().getWriter().write(json);
16             ServletActionContext.getResponse().getWriter().flush();
17         } catch (IOException e) {
18             // TODO Auto-generated catch block
19             e.printStackTrace();
20         }
21         
22         //writeJson(json);
23     }
24     
25     
26     /*public String uploadFile(String path){
27         return uploadFile(getUploadFileName(), path, 500 * 1024, false);
28     }*/
29     
30     /**
31      * 上传文件
32      * @param filename  文件名
33      * @param path      文件保存路径
34      * @param maxSize   上传文件的最大大小
35      * @param overwrite 是否覆盖已存在的文件
36      * @return
37      */
38     public Json uploadFile(String filename, String path, long maxSize, boolean overwrite){
39         Json j = new Json();
40         JSONObject jsonObject = new JSONObject();
41         JSONArray jsonArray = new JSONArray();
42         String fileName = filename;
43         String msg = "文件上传成功!";
44         if (! overwrite) {
45             //检查并得到新的保存文件名,防止重名后覆盖已存在的文件
46             fileName = FileUtils.checkFileName(filename, path);
47             if (FileUtils.isFileExist(fileName, path)) {
48                 /*FileDownloadUtils.downloadJSON("{success:false, msg:'上传文件名已存在,请改名后重新上传!'}",
49                         getResponse());*/
50                 msg = "上传文件名已存在,请改名后重新上传!";
51                 return null;
52             }
53         }
54         if (upload == null) {
55             /*FileDownloadUtils.downloadJSON("{success:false, msg:'文件名及路径名有问题,请修改后重新上传!'}",
56                     getResponse());*/
57             msg = "文件名及路径名有问题,请修改后重新上传!";
58             return null;
59         }
60         try {
61             if (upload.length()> maxSize) {
62                 /*FileDownloadUtils.downloadJSON("{success:false, msg:'上传文件不能大于" + maxSize +",请修改后重新上传!'}",
63                         getResponse());*/
64                 msg = "上传文件不能大于" + maxSize +",请修改后重新上传!";
65                 return null;
66             }
67             FileUtils.uploadForName(fileName, path, upload);
68         } catch (IOException e) {
69             e.printStackTrace();
70             /*FileDownloadUtils.downloadJSON("{success:false, msg:'文件上传失败!'}",
71                     getResponse());*/
72             msg = "文件上传失败!";
73             return null;
74         }
75         j.setSuccess(true);
76         j.setMsg(msg);
77         jsonObject.put("name", fileName);
78         jsonObject.put("type", FileUtils.converContentType(getUploadContentType()));
79         jsonObject.put("size", upload.length());
80         jsonArray.add(jsonObject);
81         j.setObj(jsonArray);
82         /*FileDownloadUtils.downloadJSON(
83                 "{success:true, msg:'文件上传成功!', " + 
84                 "file: {name:'" + fileName +
85                 "', type:'" + FileUtils.converContentType(getUploadContentType()) + 
86                 "', size:" + upload.length() + "}}",
87                 getResponse());*/
88         
89         //errMessage="文件上传成功!";
90         //success = true;
91         return j;
92     }



转自 :http://jq09.com/forum.php?mod=viewthread&tid=346

原文地址:https://www.cnblogs.com/XiaoGer/p/2794797.html