利用Swfupload组件和javaScript实现文件排量上传文件
来源:互联网 发布:原生js获取兄弟元素 编辑:程序博客网 时间:2024/04/28 00:15
首先是配置swfupload组件
可以参考swfupload组件的官方网址,先阅读官方网站的英文文档,了解swfupload组件的配置,下面的代码如下
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.cyzt.util.*"%>
<%
String tablename=request.getParameter("tablename");
String tableidname=request.getParameter("tableidname");
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
StringBuffer uploadUrl = new StringBuffer("http://");
uploadUrl.append(request.getHeader("Host"));
uploadUrl.append(request.getContextPath());
uploadUrl.append("/mulitupload.do?action=upload");
out.clear();
Pubutil Pub=new Pubutil();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="css/button.css" type="text/css" />
<script type="text/javascript" src="js/swfupload/swfupload.js"></script>
<script type="text/javascript" src="js/swfupload/swfupload.queue.js"></script>
<script type="text/javascript" src="js/swfupload/handlers.js"></script>
<script type="text/javascript">
var swfu;
window.onload = function () {
swfu = new SWFUpload({
upload_url: "<%=uploadUrl.toString()%>&tablename=<%=tablename%>&tableidname=<%=tableidname%>",
post_params: {"name" : "yangjian"},
// File Upload Settings
file_size_limit : "100 MB", // 100MB
file_types : "*.*",
file_types_description : "所有文件",
file_upload_limit : "100",//上传文件个数限制
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,//选择好文件后提交
file_queued_handler: fileQueued,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
// Button Settings
button_image_url : "images/SmallSpyGlassWithTransperancy_17x18.png",
button_placeholder_id : "spanButtonPlaceholder",
button_width: 250,
button_height: 18,
button_text : '<span class="button">选择文件 </span>',
button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 12pt; }',
button_text_top_padding: 0,
button_text_left_padding: 0,
button_left:0,
button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
button_cursor: SWFUpload.CURSOR.HAND,
// Flash Settings
flash_url : "js/swfupload/swfupload.swf",
custom_settings : {
upload_target : "divFileProgressContainer"
},
// Debug Settings
debug: false //是否显示调试窗口
});
};
function startUploadFile(){
swfu.startUpload();
}
</script>
</head>
<body>
<form id="form1" action="" method="post" enctype="multipart/form-data">
<div
style="display: inline; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;height:30px;width:500px">
<span id="spanButtonPlaceholder"></span>
<input id="btnUpload" type="button" value="上 传"
onclick="startUploadFile();" class="btn3_mouseout"
onMouseUp="this.className='btn3_mouseup'"
onmousedown="this.className='btn3_mousedown'"
onMouseOver="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'" />
<input id="btnCancel" type="button" value="取消所有上传"
onclick="cancelUpload();" disabled="disabled"
class="btn3_mouseout" onMouseUp="this.className='btn3_mouseup'"
onmousedown="this.className='btn3_mousedown'"
onMouseOver="this.className='btn3_mouseover'"
onmouseout="this.className='btn3_mouseout'" />
</div>
</form>
<div id="divFileProgressContainer"></div>
<div id="thumbnails">
<table id="infoTable" border="0" width="500px"
style="display: inline; border: solid 1px; background-color: #C5D9FF; padding: 2px;height:30px;margin-top:5px">
</table>
</div>
下面是相对应的MultiUploadAction相应的代码
package com.cyzt.sys.action;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.cyzt.sys.service.MultiUploadService;
import com.cyzt.sys.service.TpictureService;
public class MultiUploadAction extends DispatchAction {
public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
String filename=null;
MultiUploadService ms=new MultiUploadService();
TpictureService ts=new TpictureService();
String tablename=request.getParameter("tablename");
String tableidname=request.getParameter("tableidname");
try {
request.setCharacterEncoding("UTF-8");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
System.out.println("request:" + request);
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) } else {
String fieldName = item.getFieldName();
String fileName = item.getName();
long sizeInBytes = item.getSize();
getListInSession(request).add(fileName);
getListInSession(request).add(UUID.randomUUID());
String filePath = this.getServlet().getServletContext().getRealPath("/") + "upload/" + "project/";
String newfilePath=filePath.replace("//", "/");
File savePath = new File(filePath);
fileName=ms.RenamePictrue(tablename,fileName);
ts.addPictureInfoMation(tablename, tableidname, newfilePath, fileName);
System.out.println(savePath.getAbsolutePath());
if (!savePath.exists()) {
savePath.mkdir();
}
item.write(new File(filePath + fileName));
}
}
System.out.println("-------- final--------");
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public List getListInSession(HttpServletRequest request) {
List result = (List) request.getSession().getAttribute("_result");
if (result == null) {
result = new ArrayList();
request.getSession().setAttribute("_result", result);
}
return result;
}
}
</body>
</html>
- 利用Swfupload组件和javaScript实现文件排量上传文件
- 利用SWFupload实现表单上传大文件
- apache文件上传组件+oracle+SWFupload实现文件上传
- SWFUpload多文件上传组件
- 文件上传组件SWFUpload 介绍
- SWFUpload 和Extjs3.3 + swfUpload2.2 实现多文件上传组件
- Swfupload实现多文件上传
- Swfupload实现多文件上传
- 利用swfupload上传大文件汉化版
- SWFUpload实现多文件上传DEMO
- 使用swfUpload实现现文件上传
- SWFUpload 批量上传文件
- SWFUpload上传文件
- 使用SWFUpload上传文件
- SWFUpload 上传文件控件
- swfupload上传大文件
- 文件上传swfupload
- 使用SWFUpload上传文件
- 健康长寿饮食方
- 悬而未决:谁知道Apache2.2.15中apr_dbd_mysql-1.dll和PHP5.2.13中libmysql.dll的作用?
- OOA
- 0707
- Linux里常见术语的缩写
- 利用Swfupload组件和javaScript实现文件排量上传文件
- OOD
- Rational ClearQuest介绍功能简介
- 0708
- 0708+0709
- C udp 组播
- OTPs: Using s/Key with SSH via OPIE
- 基于mini2440的QT程序移植
- 感悟