javascript

首页 新闻 论坛 问答 博客 招聘 更多 ▼ 专栏

圈子

搜索
您还未登录 ! 我的应用 登录 注册 stephen830永久域名 http://stephen830.iteye.com49顶
4踩感谢朋友们在阅读文章的时候能为我指出毛病 ... | java生成条形码 2008-10-21
step-by-step多文件WEB批量上传(swfupload)的完美解决方案
文章分类:Java编程 关键字: swfupload java/jsp批量上传文件
★★★ 本篇为原创,需要引用转载的朋友请注明:《 http://stephen830.iteye.com/blog/255583 》 谢谢支持! ★★★

功能完全支持ie和firefox浏览器!同样也支持safari浏览器!

一般的WEB方式文件上传只能一个一个的进行上传,在某些应用上就显得很不人性化,客户们都希望能够1次选择很多文件,然后让系统把选择的文件全部上传。

这里,就将针对这个问题提出一个比较完美的解决方案,利用的技术主要有2个:Flash 和 smartupload。Flash 能够让客户一次选择多个文件,而smartupload负责将选择的文件上传到服务器上。

有些朋友看到这里,就知道了,其实就是swfupload方法,具体信息可以访问swfupload官方网站:http://www.swfupload.org/

让我们先来看看客户端的界面效果图。(多选文件,批量上传,上传进度显示)



要做到图中的效果,其实很方便,看完下面的描述,相信大家都可以实现上图中的效果了。
说明:swfupload2中通过一个png图片与flash插件进行关联,可以修改images下的png图片来(如上图中的[选择文件]图片)自定义显示自己想要的图片样子(不要修改图片名字和格式)。

如果你用的不是java环境,不要紧,只要稍作修改,同样可以使用在其他的环境中。

第1步,要进行下面的过程,必须先准备好Flash插件和smartupload。
Flash插件:相信大家的浏览器早已经安装过了,请检查版本,尽量使用最新的的flash插件。

smartupload:大家可以去看看我的另一篇文章 [上传下载组件SmartUpload使用方法] http://stephen830.iteye.com/blog/255010 里面详细讲述了使用方法,并且提供了具体java类的下载。请先熟悉smartupload,然后再开始下面的步骤。

第2步,前台部分准备客户操作的WEB界面,如下[UploadFileExample.jsp、UploadFileExampleSubmit.jsp]


(关于参数 upload_url: "<%=uploadUrl.toString()%>",
要注意提交文件路径,最好用http://.../UploadFileExample.jsp格式的完整路径,即像我例子中写的那样)

UploadFileExample.jsp
Html代码
<%@ page contentType="text/html;charset=UTF-8"%>
<%
double perMaxSize = 1.5;//单个文件允许的max大小
String sizeUnit = "MB";//perMaxSize数据对应的单位
String ext = "*.jpg;*.jpeg;*.gif";//允许上传的文件类型
//文件上传提交的目标页面
StringBuffer uploadUrl = new StringBuffer("http://");
uploadUrl.append(request.getHeader("Host"));
uploadUrl.append(request.getContextPath());
uploadUrl.append("/admin/swfuploadexample/UploadFileExampleSubmit.jsp");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>批量相片上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/swfupload.swfobject.js"></script>
<script type="text/javascript" src="js/swfupload.queue.js"></script>
<script type="text/javascript" src="js/fileprogress.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>

<script type="text/javascript">
var swfu;

SWFUpload.onload = function () {
var settings = {
flash_url : "js/swfupload.swf",
upload_url: "<%=uploadUrl.toString()%>",
post_params: {
"user_id" : "stephen830",
"pass_id" : "123456"
},
file_size_limit : "<%=perMaxSize%> <%=sizeUnit%>",
file_types : "<%=ext%>",
file_types_description : "<%=ext%>",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel",
uploadButtonId : "btnUpload",
myFileListTarget : "idFileList"
},
debug: false,
auto_upload:false,

// Button Settings
button_image_url : "images/XPButtonUploadText_61x22.png", // Relative to the SWF file
button_placeholder_id : "spanButtonPlaceholder",
button_width: 61,
button_height: 22,

// The event handler functions are defined in handlers.js
swfupload_loaded_handler : swfUploadLoaded,
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete, // Queue plugin event

// SWFObject settings
minimum_flash_version : "9.0.28",
swfupload_pre_load_handler : swfUploadPreLoad,
swfupload_load_failed_handler : swfUploadLoadFailed
};

swfu = new SWFUpload(settings);
}

</script>
</head>
<body bgcolor="#FCFCFC" topmargin="0px" leftmargin="10px" rightmargin="10px" scroll="yes">
<table width="100%" cellspacing="4" cellpadding="4" border="0" bgcolor="#FCFCFC">
<tr>
<td class="DH1">
<table width="100%" cellspacing="4" cellpadding="4" border="0" bgcolor="#FCFCFC">
<tr>
<td class="DH2">
<STRONG>批量上传相片 (支持的相片类型:<%=ext%>;单个相片最大不能超过:<%=perMaxSize%> <%=sizeUnit%>)</STRONG>
</td><td class="DH2" align="right"></td>
</tr>
</table>
<div id="content">
<form id="form1" action="UploadFileExampleSubmit.jsp" method="post" enctype="multipart/form-data">
<table width="90%" cellspacing="0" cellpadding="0" border="0"><tr><td>
<span id="spanButtonPlaceholder"></span>
<input id="btnUpload" type="button" value="上传相片" class="btn" />
<input id="btnCancel" type="button" value="取消全部上传" disabled="disabled" class="btn" /></td>
</tr></table>
<table id="idFileList" class="uploadFileList"><tr class="uploadTitle"><td><B>文件名</B></td><td><B>文件大小</B></td><td width=100px><B>状态</B></td><td width=35px> </td></tr></table>
等待上传 <span id="idFileListCount">0</span> 个 ,成功上传 <span id="idFileListSuccessUploadCount">0</span> 个
<div id="divSWFUploadUI" style="visibility: hidden;"></div>
<noscript style="display: block; margin: 10px 25px; padding: 10px 15px;">
很抱歉,相片上传界面无法载入,请将浏览器设置成支持JavaScript。
</noscript>
<div id="divLoadingContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
相片上传界面正在载入,请稍后...
</div>
<div id="divLongLoading" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
相片上传界面载入失败,请确保浏览器已经开启对JavaScript的支持,并且已经安装可以工作的Flash插件版本。
</div>
<div id="divAlternateContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
很抱歉,相片上传界面无法载入,请安装或者升级您的Flash插件。
请访问: <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Adobe网站</a> 获取最新的Flash插件。
</div>
</form>
</div>
</td></tr></table>
</body>
</html>

<%@ page contentType="text/html;charset=UTF-8"%>
<%
double perMaxSize = 1.5;//单个文件允许的max大小
String sizeUnit = "MB";//perMaxSize数据对应的单位
String ext = "*.jpg;*.jpeg;*.gif";//允许上传的文件类型
//文件上传提交的目标页面
StringBuffer uploadUrl = new StringBuffer("http://");
uploadUrl.append(request.getHeader("Host"));
uploadUrl.append(request.getContextPath());
uploadUrl.append("/admin/swfuploadexample/UploadFileExampleSubmit.jsp");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>批量相片上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/swfupload.js"></script>
<script type="text/javascript" src="js/swfupload.swfobject.js"></script>
<script type="text/javascript" src="js/swfupload.queue.js"></script>
<script type="text/javascript" src="js/fileprogress.js"></script>
<script type="text/javascript" src="js/handlers.js"></script>

<script type="text/javascript">
var swfu;

SWFUpload.onload = function () {
var settings = {
flash_url : "js/swfupload.swf",
upload_url: "<%=uploadUrl.toString()%>",
post_params: {
"user_id" : "stephen830",
"pass_id" : "123456"
},
file_size_limit : "<%=perMaxSize%> <%=sizeUnit%>",
file_types : "<%=ext%>",
file_types_description : "<%=ext%>",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel",
uploadButtonId : "btnUpload",
myFileListTarget : "idFileList"
},
debug: false,
auto_upload:false,

// Button Settings
button_image_url : "images/XPButtonUploadText_61x22.png", // Relative to the SWF file
button_placeholder_id : "spanButtonPlaceholder",
button_width: 61,
button_height: 22,

// The event handler functions are defined in handlers.js
swfupload_loaded_handler : swfUploadLoaded,
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete, // Queue plugin event

// SWFObject settings
minimum_flash_version : "9.0.28",
swfupload_pre_load_handler : swfUploadPreLoad,
swfupload_load_failed_handler : swfUploadLoadFailed
};

swfu = new SWFUpload(settings);
}

</script>
</head>
<body bgcolor="#FCFCFC" topmargin="0px" leftmargin="10px" rightmargin="10px" scroll="yes">
<table width="100%" cellspacing="4" cellpadding="4" border="0" bgcolor="#FCFCFC">
<tr>
<td class="DH1">
<table width="100%" cellspacing="4" cellpadding="4" border="0" bgcolor="#FCFCFC">
<tr>
<td class="DH2">
<STRONG>批量上传相片 (支持的相片类型:<%=ext%>;单个相片最大不能超过:<%=perMaxSize%> <%=sizeUnit%>)</STRONG>
</td><td class="DH2" align="right"></td>
</tr>
</table>
<div id="content">
<form id="form1" action="UploadFileExampleSubmit.jsp" method="post" enctype="multipart/form-data">
<table width="90%" cellspacing="0" cellpadding="0" border="0"><tr><td>
<span id="spanButtonPlaceholder"></span>
<input id="btnUpload" type="button" value="上传相片" class="btn" />
<input id="btnCancel" type="button" value="取消全部上传" disabled="disabled" class="btn" /></td>
</tr></table>
<table id="idFileList" class="uploadFileList"><tr class="uploadTitle"><td><B>文件名</B></td><td><B>文件大小</B></td><td width=100px><B>状态</B></td><td width=35px> </td></tr></table>
等待上传 <span id="idFileListCount">0</span> 个 ,成功上传 <span id="idFileListSuccessUploadCount">0</span> 个
<div id="divSWFUploadUI" style="visibility: hidden;"></div>
<noscript style="display: block; margin: 10px 25px; padding: 10px 15px;">
很抱歉,相片上传界面无法载入,请将浏览器设置成支持JavaScript。
</noscript>
<div id="divLoadingContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
相片上传界面正在载入,请稍后...
</div>
<div id="divLongLoading" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
相片上传界面载入失败,请确保浏览器已经开启对JavaScript的支持,并且已经安装可以工作的Flash插件版本。
</div>
<div id="divAlternateContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
很抱歉,相片上传界面无法载入,请安装或者升级您的Flash插件。
请访问: <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Adobe网站</a> 获取最新的Flash插件。
</div>
</form>
</div>
</td></tr></table>
</body>
</html>


UploadFileExample.jsp对应的处理页面 --> UploadFileExampleSubmit.jsp

(1)请确保已经看完我的另一篇文章(上传下载组件SmartUpload使用方法 http://stephen830.iteye.com/admin/blogs/255010),先搞好这个才能开始下面的操作
(2)写一个对应上传方法类,com.soft4j.bo.PhotoMgr.java,其中的方法就是文章下面提到的public static String fileUpload(SmartUpload su,PageContext pageContext) throws Exception {...}

这2点弄好了,ok,可以继续。(如果没有准备java文件,下面的UploadFileExampleSubmit.jsp会报错)

注意在(UploadFileExampleSubmit.jsp)中:上传成功后必须返回“successed”,失败的话则返回失败的原因。

Html代码
<%@ page contentType="text/html;charset=UTF-8"%><%@ page import="com.soft4j.httpupload4j.SmartUpload"%><%@ page import="com.soft4j.bo.PhotoMgr"%><%
String pageErrorInfo = null;
SmartUpload su = null;
try{
su = new SmartUpload();
su.initialize(pageContext);
su.upload();
pageErrorInfo = PhotoMgr.fileUpload(su,pageContext);
if(pageErrorInfo==null){
out.print("successed");
}
}catch(Exception e){
pageErrorInfo = e.getMessage();
}finally{
su = null;
if(pageErrorInfo!=null){
out.print(pageErrorInfo);
}
}
%>

<%@ page contentType="text/html;charset=UTF-8"%><%@ page import="com.soft4j.httpupload4j.SmartUpload"%><%@ page import="com.soft4j.bo.PhotoMgr"%><%
String pageErrorInfo = null;
SmartUpload su = null;
try{
su = new SmartUpload();
su.initialize(pageContext);
su.upload();
pageErrorInfo = PhotoMgr.fileUpload(su,pageContext);
if(pageErrorInfo==null){
out.print("successed");
}
}catch(Exception e){
pageErrorInfo = e.getMessage();
}finally{
su = null;
if(pageErrorInfo!=null){
out.print(pageErrorInfo);
}
}
%>


第3步 准备后台的文件上传功能。也就是上面文件[UploadFileExampleSubmit.jsp]中用到的[PhotoMgr.fileUpload(su,pageContext)]方法。

Java代码
/**
* 文件上传方法.
* @param su
* @param pageContext
* @return
* @throws Exception
*/
public static String fileUpload(SmartUpload su,PageContext pageContext) throws Exception {
com.soft4j.httpupload4j.File suFile = null;
int fileCount = 0;
try {
//获取传递过来的参数
String userId = su.getRequest().getParameter("user_id");
String passId = su.getRequest().getParameter("pass_id");

String fileExt = "";
int fileSize = 0;
String AllowedExtensions = ",jpg,jpeg,gif,";//允许上传的文件类型
double maxFileSize = 1.5*1024;//单文件最大大小,单位KB
//校验文件类型和大小
for (int i=0; i<su.getFiles().getCount();i++) {
suFile = su.getFiles().getFile(i);
if (suFile.isMissing())
continue;
//校验文件大小
fileSize = suFile.getSize()/1024;//字节转换成KB
if(fileSize==0) fileSize=1;
if(maxFileSize<fileSize) throw new Exception("单个上传相片的容量不能超过["+maxFileSize+"KB]");

//校验文件类型
if (suFile.getFileExt() == null
|| "".equals(suFile.getFileExt())) {
fileExt = ",,";
} else {
fileExt = "," + suFile.getFileExt().toLowerCase() + ",";
}
if (!"".equals(AllowedExtensions)
&& AllowedExtensions.indexOf(fileExt) == -1) {
throw new Exception("您上传的文件[" + suFile.getFileName()
+ "]的类型为系统禁止上传的文件类型,不能上传!");
}
fileCount++;
}
if (fileCount==0) throw new Exception("请选择上传的文件");
//准备保存文件
String filePath="D:\\tomcat\\webapps\\test\\photo\\";//这里填写项目中存放上传文件的物理路径
for (int i=0; i<su.getFiles().getCount();i++) {
suFile = su.getFiles().getFile(i);
suFile.saveAs(filePath+suFile.getFileName(),SmartUpload.SAVE_PHYSICAL);//保存文件
}
//成功返回null
return null;
} finally {
//
}
}

/**
* 文件上传方法.
* @param su
* @param pageContext
* @return
* @throws Exception
*/
public static String fileUpload(SmartUpload su,PageContext pageContext) throws Exception {
com.soft4j.httpupload4j.File suFile = null;
int fileCount = 0;
try {
//获取传递过来的参数
String userId = su.getRequest().getParameter("user_id");
String passId = su.getRequest().getParameter("pass_id");

String fileExt = "";
int fileSize = 0;
String AllowedExtensions = ",jpg,jpeg,gif,";//允许上传的文件类型
double maxFileSize = 1.5*1024;//单文件最大大小,单位KB
//校验文件类型和大小
for (int i=0; i<su.getFiles().getCount();i++) {
suFile = su.getFiles().getFile(i);
if (suFile.isMissing())
continue;
//校验文件大小
fileSize = suFile.getSize()/1024;//字节转换成KB
if(fileSize==0) fileSize=1;
if(maxFileSize<fileSize) throw new Exception("单个上传相片的容量不能超过["+maxFileSize+"KB]");

//校验文件类型
if (suFile.getFileExt() == null
|| "".equals(suFile.getFileExt())) {
fileExt = ",,";
} else {
fileExt = "," + suFile.getFileExt().toLowerCase() + ",";
}
if (!"".equals(AllowedExtensions)
&& AllowedExtensions.indexOf(fileExt) == -1) {
throw new Exception("您上传的文件[" + suFile.getFileName()
+ "]的类型为系统禁止上传的文件类型,不能上传!");
}
fileCount++;
}
if (fileCount==0) throw new Exception("请选择上传的文件");
//准备保存文件
String filePath="D:\\tomcat\\webapps\\test\\photo\\";//这里填写项目中存放上传文件的物理路径
for (int i=0; i<su.getFiles().getCount();i++) {
suFile = su.getFiles().getFile(i);
suFile.saveAs(filePath+suFile.getFileName(),SmartUpload.SAVE_PHYSICAL);//保存文件
}
//成功返回null
return null;
} finally {
//
}
}


备注:关于jsp页面和java方法我不做过多的说明了,应该已经比较清楚了。

本文自发布后,受到了很多朋友的关注,也为不少的朋友提供了帮助,我很高兴。
下面将朋友们遇到的一些问题作汇总后需要注意的一些地方列了出来:

<1> 功能实现需要flash插件支持。
flash版本为 flash 9.0.124 或者 flash 10.0.12.36 版本(这是最新的flash10插件). 如果不是的话,可以去flash官网 http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash 进行在线安装。


<2> UploadFileExample.jsp 中的 upload_url参数设置。
参数需要使用 http://....../UploadFileExampleSubmit.jsp 这样的完整路径.

<3> 关于获取参数 post_params中的参数值。
post_params: {"user_id" : "stephen830","pass_id" : "123456"} 中的参数,不能使用普通的request.getParameter("")方法来获取,
而必须用你的上传方法对应的特定方法来获取,比如,我这里用smartupload,则获取方法就是String userId = su.getRequest().getParameter("user_id");

<4> 上传后不管成功还是失败,都需要有返回值。
这个返回值将传递到对应js中。返回值在UploadFileExampleSubmit.jsp中设置,成功则 out.print("successed"); 失败则 out.print(pageErrorInfo);//pageErrorInfo为错误信息。

该返回值将传递给js目录下的handlers.js文件,具体的方法是 function uploadSuccess(file, serverData) {...} 。

有些朋友的上传成功后out.print("successed"); 发现js收到的"successed"前面会有隐藏字符,遇到这种情况可以更改function uploadSuccess(file, serverData) {...} 中的
var isSuccess = (serverData.indexOf("successed")==0?true:false);
改为
var isSuccess = (serverData.indexOf("successed")>-1?true:false);
就可以了。

<5> 附件中增加一个完整的测试功能例子。
附件名 PROJECT_swfupload.zip 下载 http://stephen830.iteye.com/upload/attachment/53105/e0e90839-a760-3adb-acdd-aa3b972d090c.zip


附录:swfupload 文件批量上传压缩包 swfupload.zip(支持最新的flash10插件) (附件中没有java类,请自己准备1个java类,将上面的方法复制进去)

为方便了解和调试功能,在附件中增加了一个完整的工程Example,附件名(PROJECT_swfupload.zip),大家可以直接使用来测试功能。

最后感谢朋友 flyfan,taiwei 对本篇的建议!
-------------------------------------------------------------
分享知识 分享快乐,分享知识,分享快乐,希望文章能给需要的朋友带来小小的帮助。

swfupload.zip (44.4 KB)
下载次数: 2257

大小: 18.5 KB
PROJECT_swfupload.zip (99.3 KB)
下载次数: 2433
查看图片附件
49
顶4

感谢朋友们在阅读文章的时候能为我指出毛病 ... | java生成条形码 06:50 浏览 (19296) 评论 (148) 分类: java 相关推荐 评论
148 楼 sunwang810812 2010-12-17 引用
楼主是好人,找了N久,才找到这样的好文章^
147 楼 sunwang810812 2010-12-17 引用
xiaoqulai 写道
代码太多,你为什么不试试我的批量上传工具,超级简单,只需要往jsp里面插入三句话
推荐你看看: AlanXUpload 批量上传

这个网站打不开啊,能告诉我你是怎么用的吗?我的email:tosswang@163.com,谢谢
146 楼 南方觅雪 2010-10-27 引用
怎么下载不了附件,有两次下载下来了,但不是工程文件,是其它一些不相关的东西
145 楼 hyling927 2010-09-16 引用
请问楼主,是啥时候调用的UploadFileExampleSubmit.jsp页面 啊?为什么我在上传相片按钮的事件里没有找到呢?

144 楼 wgcniler 2010-02-26 引用
swfupload自250版本后支持resize功能,请问版主在您这里的基础上如何加上resize功能.
143 楼 joker_yao 2009-12-03 引用
我测试通过了 但是我改成提交到 servlet 就没反应了?为什么呢

142 楼 xiaoqulai 2009-12-01 引用
代码太多,你为什么不试试我的批量上传工具,超级简单,只需要往jsp里面插入三句话
推荐你看看: AlanXUpload 批量上传
141 楼 wgcniler 2009-11-02 引用
请问在上传图片前能对图片进行压缩么?如何实现?
140 楼 wgcniler 2009-10-15 引用
sbswcidr 写道
:cry: 太感谢了。。。
找了三天没找到的东西。。。
终于找到了。。

我试了一下。。我用的是struts2上传的。。发现有几处地方有问题
1.在action里面要定义这三个属性才能接收到文件的相关信息,不知道可否修改这个属性的名字。不知道在哪修改。
Java代码
/** 文件对象 */
private List<File> filedata;

/** 文件名 */
private List<String> filedataFileName;

/** 文件内容类型 */
private List<String> filedataContentType;

/**
* @return the filedata
*/
public List<File> getFiledata() {
return filedata;
}

/**
* @param filedata the filedata to set
*/
public void setFiledata(List<File> filedata) {
this.filedata = filedata;
}

/**
* @return the filedataFileName
*/
public List<String> getFiledataFileName() {
return filedataFileName;
}

/**
* @param filedataFileName the filedataFileName to set
*/
public void setFiledataFileName(List<String> filedataFileName) {
this.filedataFileName = filedataFileName;
}

/**
* @return the filedataContentType
*/
public List<String> getFiledataContentType() {
return filedataContentType;
}

/**
* @param filedataContentType the filedataContentType to set
*/
public void setFiledataContentType(List<String> filedataContentType) {
this.filedataContentType = filedataContentType;
}

/** 文件对象 */
private List<File> filedata;

/** 文件名 */
private List<String> filedataFileName;

/** 文件内容类型 */
private List<String> filedataContentType;

/**
* @return the filedata
*/
public List<File> getFiledata() {
return filedata;
}

/**
* @param filedata the filedata to set
*/
public void setFiledata(List<File> filedata) {
this.filedata = filedata;
}

/**
* @return the filedataFileName
*/
public List<String> getFiledataFileName() {
return filedataFileName;
}

/**
* @param filedataFileName the filedataFileName to set
*/
public void setFiledataFileName(List<String> filedataFileName) {
this.filedataFileName = filedataFileName;
}

/**
* @return the filedataContentType
*/
public List<String> getFiledataContentType() {
return filedataContentType;
}

/**
* @param filedataContentType the filedataContentType to set
*/
public void setFiledataContentType(List<String> filedataContentType) {
this.filedataContentType = filedataContentType;
}
2.如果上传的文件文件名包含中文字符的话。上传不了。这个可能是要转编码之类的。我还没试过。
3.一切准备好了之后我开始上传了,可是发现文件是有传上去了。。而且其它的业务数据也有保存进去了。可是界面上还是显示等待上传字样,于是我认真仔细看了一下原来是这样子的啊,晕,心太急了
是因为我上传是提交到后台action处理的,所以一开始没注意看UploadFileExampleSubmit.jsp这段代码
Java代码
if(pageErrorInfo==null){
out.print("successed");
}

if(pageErrorInfo==null){
out.print("successed");
}

我Action返回的是null,后来改了一下就OK了。
应改为Java代码
public String saveFiles(){
try{
HttpServletResponse response = ServletActionContext.getResponse();
//此处得到文件执行上传操作,并保存相关的业务数据 response.getWriter().write("successed");
}catch(Exception e){
e.printStackTrace();
}
return null;
}

public String saveFiles(){
try{
HttpServletResponse response = ServletActionContext.getResponse();
//此处得到文件执行上传操作,并保存相关的业务数据 response.getWriter().write("successed");
}catch(Exception e){
e.printStackTrace();
}
return null;
}


非常感谢LZ。。。您是好人啊。。。。


应该是改动swfupload.js文件中的"file_post_name";
另外,用struts2的action上传是如果上传成功后要调用this.getResponse().getWriter().print("successed");这样成功上传一个文件后才会进行下一个文件的上传,否则会一直处于等待中.

我觉得采用struts2作为上传更简单一线,上传页面(UploadFileExample.jsp
)基本上除了把" uploadUrl.append("/admin/swfuploadexample/UploadFileExampleSubmit.jsp"); "这个改为上传的action,例如我的改为"uploadUrl.append("/swfupload.do");",别的和普通的上传代码是一样的.
139 楼 sbswcidr 2009-09-28 引用
用这个上传。。后台是用struts2 编写的。。可是传文件名是中文的会乱码。。。

经过一段时间的思考。。。。

result = new String(str1.getBytes("GBK"),"UTF-8");

这样子转换出来。。会有正确的中文转换出来。。

但是当中文个数是偶数个的时候转换是没有问题的。。

可是如果是奇数个的时候就会有个别字转换不了。。

有人知道是怎么回事吗?

怎么解决?

谢谢。。。
138 楼 sjpsega 2009-09-07 引用
哥们,不错,顶一个。
这个弄了好久,原先的只能支持Flash 9 ,现在要支持Flash 10 ,累人啊……
137 楼 zhongxiaoyi738 2009-09-07 引用
上传成功之后报错

---SWFUpload Instance Info---
Version: 2.2.0 Beta 2
Movie Name: SWFUpload_0
Settings:
upload_url: /ngchnl/webpage/upload/doUpload.jsp
flash_url: /ngchnl/swpupload/flash/swfupload.swf?swfuploadrnd=772795929
use_query_string: false
requeue_on_error: false
http_success:
file_post_name: Filedata
post_params: [object Object]
file_types: *.txt;*.xls;*.gif
file_types_description: *.txt;*.xls;*.gif
file_size_limit: 10 MB
file_upload_limit: 10
file_queue_limit: 0
debug: true
prevent_swf_caching: true
button_placeholder_id: spanButtonPlaceHolder
button_image_url: /ngchnl/swpupload/images/XPButtonUploadText_61x22.png
button_width: 65
button_height: 29
button_text: <span class="theFont">选择文件</span>
button_text_style: .theFont { font-size: 10; }
button_text_top_padding: 3
button_text_left_padding: 12
button_action: -110
button_disabled: false
custom_settings: [object Object]
Event Handlers:
swfupload_loaded_handler assigned: false
file_dialog_start_handler assigned: false
file_queued_handler assigned: true
file_queue_error_handler assigned: true
upload_start_handler assigned: true
upload_progress_handler assigned: true
upload_error_handler assigned: true
upload_success_handler assigned: true
upload_complete_handler assigned: true
debug_handler assigned: true

SWFUpload.SWFObject Plugin settings:
minimum_flash_version: 9.0.28
swfupload_pre_load_handler assigned: false
swfupload_load_failed_handler assigned: false

SWF DEBUG: SWFUpload Init Complete
SWF DEBUG:
SWF DEBUG: ----- SWF DEBUG OUTPUT ----
SWF DEBUG: Build Number: SWFUPLOAD 2.2.0 Beta 2 2008-10-28
SWF DEBUG: movieName: SWFUpload_0
SWF DEBUG: Upload URL: /ngchnl/webpage/upload/doUpload.jsp
SWF DEBUG: File Types String: *.txt;*.xls;*.gif
SWF DEBUG: Parsed File Types: txt,xls,gif
SWF DEBUG: HTTP Success: 0
SWF DEBUG: File Types Description: *.txt;*.xls;*.gif (*.txt;*.xls;*.gif)
SWF DEBUG: File Size Limit: 10485760 bytes
SWF DEBUG: File Upload Limit: 10
SWF DEBUG: File Queue Limit: 10
SWF DEBUG: Post Params:
SWF DEBUG: op_id=9009
SWF DEBUG: ----- END SWF DEBUG OUTPUT ----
SWF DEBUG:
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.txt;*.xls;*.gif
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_1
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 2. Files Queued: 2
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
SWF DEBUG: Global Post Item: op_id=9009
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to /ngchnl/webpage/upload/doUpload.jsp for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 927. Total: 927
SWF DEBUG: Event: uploadSuccess: File ID: SWFUpload_0_0 Data:
SWF DEBUG: successed
SWF DEBUG: Event: uploadComplete : Upload cycle complete.
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_1
SWF DEBUG: Global Post Item: op_id=9009
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to /ngchnl/webpage/upload/doUpload.jsp for File ID: SWFUpload_0_1
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_1
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_1. Bytes: 927. Total: 927
SWF DEBUG: Event: uploadSuccess: File ID: SWFUpload_0_1 Data:
SWF DEBUG: successed
SWF DEBUG: Event: uploadComplete : Upload cycle complete.
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
SWF DEBUG: Event: fileDialogStart : Browsing files. Multi Select. Allowed file types: *.txt;*.xls;*.gif
SWF DEBUG: Select Handler: Received the files selected from the dialog. Processing the file list...
SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_2
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_2
SWF DEBUG: Global Post Item: op_id=9009
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload. Starting upload to /ngchnl/webpage/upload/doUpload.jsp for File ID: SWFUpload_0_2
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_2
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_2. Bytes: 927. Total: 927
SWF DEBUG: Event: uploadSuccess: File ID: SWFUpload_0_2 Data:
SWF DEBUG: successed
SWF DEBUG: Event: uploadComplete : Upload cycle complete.
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: message: 'document.getElementById(...)' 为空或不是对象
EXCEPTION: number: -2146823281
EXCEPTION: description: 'document.getElementById(...)' 为空或不是对象

136 楼 zhongxiaoyi738 2009-09-07 引用
怎么我这里 上传文件的时候不能显示进度条

<%
/**
* 多文件上传
*/
%>
<html>
<%@ page contentType="text/html; charset=GBK"%>
<script type="text/javascript" src="<%=request.getContextPath()%>/swpupload/js/swfupload.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/swpupload/js/swfupload.swfobject.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/swpupload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/swpupload/js/fileprogress.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/swpupload/js/handlers.js"></script>


<ai:title value="多文件上传"/>
<script language="JavaScript">

var swfu;

window.onload = function () {
var settings = {
flash_url : "<%=request.getContextPath()%>/swpupload/flash/swfupload.swf",
upload_url: "<%=request.getContextPath()%>/webpage/upload/doUpload.jsp",
post_params:
{
"op_id" : "9009"
},
file_size_limit : "10 MB",
file_types : "*.txt;*.xls;*.gif",
file_types_description : "*.txt;*.xls;*.gif",
file_upload_limit : 10,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel",
uploadButtonId : "btnUpload",
myFileListTarget : "idFileList"
},
debug: true,

// Button settings
button_image_url: "<%=request.getContextPath()%>/swpupload/images/XPButtonUploadText_61x22.png",
button_width: "65",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">选择文件</span>',
button_text_style: ".theFont { font-size: 10; }",
button_text_left_padding: 12,
button_text_top_padding: 3,

// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};

swfu = new SWFUpload(settings);
}


</script>

<body bgcolor="#FCFCFC" topmargin="0px" leftmargin="10px" rightmargin="10px" scroll="yes">
<table width="100%" cellspacing="4" cellpadding="4" border="0" bgcolor="#FCFCFC">
<tr>
<td class="DH1">
<table width="100%" cellspacing="4" cellpadding="4" border="0" bgcolor="#FCFCFC">
<tr>
<td class="DH2">
<STRONG>批量上传 (支持的文件类型:*.txt;*.xls;*.gif;单个相片最大不能超过:10 MB)</STRONG>
</td><td class="DH2" align="right"></td>
</tr>
</table>
<div id="content">
<form id="form1" action="<%=request.getContextPath()%>/webpage/upload/doUpload.jsp" method="post" enctype="multipart/form-data">
<table width="90%" cellspacing="0" cellpadding="0" border="0"><tr><td>
<span id="spanButtonPlaceholder"></span>
<input id="btnUpload" type="button" value="上传相片" class="btn" />
<input id="btnCancel" type="button" value="取消全部上传" disabled="disabled" class="btn" /></td>
</tr></table>
<table id="idFileList" class="uploadFileList"><tr class="uploadTitle"><td><B>文件名</B></td><td><B>文件大小</B></td><td width=100px><B>状态</B></td><td width=35px> </td></tr></table>
等待上传 <span id="idFileListCount">0</span> 个 ,成功上传 <span id="idFileListSuccessUploadCount">0</span> 个
<div id="divSWFUploadUI" style="visibility: hidden;"></div>
<noscript style="display: block; margin: 10px 25px; padding: 10px 15px;">
很抱歉,相片上传界面无法载入,请将浏览器设置成支持JavaScript。
</noscript>
<div id="divLoadingContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
相片上传界面正在载入,请稍后...
</div>
<div id="divLongLoading" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
相片上传界面载入失败,请确保浏览器已经开启对JavaScript的支持,并且已经安装可以工作的Flash插件版本。
</div>
<div id="divAlternateContent" class="content" style="background-color: #FFFF66; border-top: solid 4px #FF9966; border-bottom: solid 4px #FF9966; margin: 10px 25px; padding: 10px 15px; display: none;">
很抱歉,相片上传界面无法载入,请安装或者升级您的Flash插件。
请访问: <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Adobe网站</a> 获取最新的Flash插件。
</div>
</form>
</div>
</td></tr></table>
</body>

</html>


135 楼 sbswcidr 2009-08-12 引用
:cry: 太感谢了。。。
找了三天没找到的东西。。。
终于找到了。。

我试了一下。。我用的是struts2上传的。。发现有几处地方有问题
1.在action里面要定义这三个属性才能接收到文件的相关信息,不知道可否修改这个属性的名字。不知道在哪修改。
Java代码
/** 文件对象 */
private List<File> filedata;

/** 文件名 */
private List<String> filedataFileName;

/** 文件内容类型 */
private List<String> filedataContentType;

/**
* @return the filedata
*/
public List<File> getFiledata() {
return filedata;
}

/**
* @param filedata the filedata to set
*/
public void setFiledata(List<File> filedata) {
this.filedata = filedata;
}

/**
* @return the filedataFileName
*/
public List<String> getFiledataFileName() {
return filedataFileName;
}

/**
* @param filedataFileName the filedataFileName to set
*/
public void setFiledataFileName(List<String> filedataFileName) {
this.filedataFileName = filedataFileName;
}

/**
* @return the filedataContentType
*/
public List<String> getFiledataContentType() {
return filedataContentType;
}

/**
* @param filedataContentType the filedataContentType to set
*/
public void setFiledataContentType(List<String> filedataContentType) {
this.filedataContentType = filedataContentType;
}

/** 文件对象 */
private List<File> filedata;

/** 文件名 */
private List<String> filedataFileName;

/** 文件内容类型 */
private List<String> filedataContentType;

/**
* @return the filedata
*/
public List<File> getFiledata() {
return filedata;
}

/**
* @param filedata the filedata to set
*/
public void setFiledata(List<File> filedata) {
this.filedata = filedata;
}

/**
* @return the filedataFileName
*/
public List<String> getFiledataFileName() {
return filedataFileName;
}

/**
* @param filedataFileName the filedataFileName to set
*/
public void setFiledataFileName(List<String> filedataFileName) {
this.filedataFileName = filedataFileName;
}

/**
* @return the filedataContentType
*/
public List<String> getFiledataContentType() {
return filedataContentType;
}

/**
* @param filedataContentType the filedataContentType to set
*/
public void setFiledataContentType(List<String> filedataContentType) {
this.filedataContentType = filedataContentType;
}
2.如果上传的文件文件名包含中文字符的话。上传不了。这个可能是要转编码之类的。我还没试过。
3.一切准备好了之后我开始上传了,可是发现文件是有传上去了。。而且其它的业务数据也有保存进去了。可是界面上还是显示等待上传字样,于是我认真仔细看了一下原来是这样子的啊,晕,心太急了
是因为我上传是提交到后台action处理的,所以一开始没注意看UploadFileExampleSubmit.jsp这段代码
Java代码
if(pageErrorInfo==null){
out.print("successed");
}

if(pageErrorInfo==null){
out.print("successed");
}

我Action返回的是null,后来改了一下就OK了。
应改为Java代码
public String saveFiles(){
try{
HttpServletResponse response = ServletActionContext.getResponse();
//此处得到文件执行上传操作,并保存相关的业务数据 response.getWriter().write("successed");
}catch(Exception e){
e.printStackTrace();
}
return null;
}

public String saveFiles(){
try{
HttpServletResponse response = ServletActionContext.getResponse();
//此处得到文件执行上传操作,并保存相关的业务数据 response.getWriter().write("successed");
}catch(Exception e){
e.printStackTrace();
}
return null;
}


非常感谢LZ。。。您是好人啊。。。。

134 楼 yuezhou1226 2009-05-28 引用
SWFUpload is not a constructor
onload()()UploadFi...ample.jsp (第 64 行)
[Break on this error] swfu = new SWFUpload(settings);


为什么我老是出现这个错误啊?实现是找不出哪儿错了!

133 楼 yuezhou1226 2009-05-28 引用
Java代码







java


java


132 楼 jimever 2009-05-21 引用
在struts里面怎么获得到上传的文件?
131 楼 33301015 2009-04-24 引用
stephen830 写道

应该没有问题,检查这个变量的值是否含有一些特殊字符~


谢谢,我再好好研究研究!
130 楼 stephen830 2009-04-23 引用
33301015 写道

请问楼主,我自己设置的参数,file_path post_params: {               "user_id" : "lance",               "pass_id" : "lance",             "file_path" : "<%=filePath%>"         }, 之后就无法显示 选择文件 那个按钮 换成下面的代码就可以 post_params: {               "user_id" : "lance",               "pass_id" : "lance",             "file_path" : filePath"         }, 我需要从其他页面转过来,并将文件上传路径带过来,然后交给PhotoMgr来处理,请问有什么办法吗?


应该没有问题,检查这个变量的值是否含有一些特殊字符~
129 楼 33301015 2009-04-23 引用
请问楼主,我自己设置的参数,file_path
post_params: {
"user_id" : "lance",
"pass_id" : "lance",
"file_path" : "<%=filePath%>"
},
之后就无法显示 选择文件 那个按钮
换成下面的代码就可以
post_params: {
"user_id" : "lance",
"pass_id" : "lance",
"file_path" : filePath"
},
我需要从其他页面转过来,并将文件上传路径带过来,然后交给PhotoMgr来处理,请问有什么办法吗?
« 上一页 1 2 3 … 7 8 下一页 »发表评论

表情图标
字体颜色: 标准深红红色橙色棕色黄色绿色橄榄青色蓝色深蓝靛蓝紫色灰色白色黑色 字体大小: 标准1 (xx-small)2 (x-small)3 (small)4 (medium)5 (large)6 (x-large)7 (xx-large) 对齐: 标准居左居中居右
提示:选择您需要装饰的文字, 按上列按钮即可添加上相应的标签
您还没有登录,请登录后发表评论(快捷键 Alt+S / Ctrl+Enter)

stephen830
浏览: 192596 次
性别:
来自: 上海

详细资料 留言簿
搜索本博客

最近访客 >>更多访客
jws21chenjing616520123houjuan1990沉默的糕点
博客分类
全部博客 (288)
java (36)
JavaScript手册-目录 (8)
JavaScript手册-Array (19)
JavaScript手册-Boolean (5)
JavaScript手册-Date (50)
JavaScript手册-Math (30)
JavaScript手册-Number (14)
JavaScript手册-RegExp (7)
JavaScript手册-String (37)
JavaScript手册-全局函数 (8)
JavaScript实用脚本 (7)
Others (20)
java-jpcap (7)
java-thread (1)
ibm文章 (3)
classloader (2)
运行环境 (8)
java-filter (2)
java-正则 (2)
oracle (1)
linux-shell (18)
wap (1)
我的相册
嬉戏
共 14 张
我的留言簿 >>更多留言
您好! 现在在做一个付款方式要采用paypal接口,我在实际测试中(sandbox ...
-- by bjgdh
您好,请问在用paypal支付时,在哪个步骤里把订单保存到数据库里?是在用户点ch ...
-- by wgcniler
受不了你 目前正不知道如何下手 你贴出来了。 顶一个
-- by sdxz622
其他分类
我的收藏 (3)
我的书籍 (3)
我的论坛主题贴 (12)
我的所有论坛贴 (104)
我的精华良好贴 (1)
我解决的问题 (6)
最近加入圈子
存档
2010-07 (1)
2010-05 (4)
2010-04 (16)
更多存档...
评论排行榜
crontab命令详解
Linux Top命令参详解
shell判断文件,目录是否存在或者具有权限
java之classloader (2)
jsp 开发wap 注意事项 (转载)



--------------------------------------------------------------------------------
声明:JavaEye文章版权属于作者,受法律保护。没有作者书面许可不得转载。若作者同意转载,必须以超链接形式标明文章原始出处和作者。
© 2003-2011 iteye.com. All rights reserved. 上海炯耐计算机软件有限公司 [ 沪ICP备05023328号 ]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
var SWFUpload; if (typeof(SWFUpload) === "function") { SWFUpload.queue = {}; SWFUpload.prototype.initSettings = (function (oldInitSettings) { return function () { if (typeof(oldInitSettings) === "function") { oldInitSettings.call(this); } this.customSettings.queue_cancelled_flag = false; this.customSettings.queue_upload_count = 0; this.settings.user_upload_complete_handler = this.settings.upload_complete_handler; this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler; this.settings.queue_complete_handler = this.settings.queue_complete_handler || null; }; })(SWFUpload.prototype.initSettings); SWFUpload.prototype.startUpload = function (fileID) { this.customSettings.queue_cancelled_flag = false; this.callFlash("StartUpload", false, [fileID]); }; SWFUpload.prototype.cancelQueue = function () { this.customSettings.queue_cancelled_flag = true; this.stopUpload(); var stats = this.getStats(); while (stats.files_queued > 0) { this.cancelUpload(); stats = this.getStats(); } }; SWFUpload.queue.uploadCompleteHandler = function (file) { var user_upload_complete_handler = this.settings.user_upload_complete_handler; var continueUpload; if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) { this.customSettings.queue_upload_count++; } if (typeof(user_upload_complete_handler) === "function") { continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true; } else { continueUpload = true; } if (continueUpload) { var stats = this.getStats(); if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) { this.startUpload(); } else if (this.customSettings.queue_cancelled_flag === false) { this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]); this.customSettings.queue_upload_count = 0; } else { this.customSettings.queue_cancelled_flag = false; this.customSettings.queue_upload_count = 0; } } }; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值