<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>SWFUpload上传大文件</title>
<script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script type="text/javascript" src="swfupload/swfupload.js"></script>
<script type="text/javascript">
function fileQueueError(file, errorCode, message) {
try {
var v = $("#mes").html();
var str = "触发fileQueueError事件,参数file:" + file + ",参数errorCode:" + errorCode + ",参数message:" + message;
$("#mes").html(v + str + "<br />");
} catch (ex) {
this.debug(ex);
}
}
function fileDialogComplete(numFilesSelected, numFilesQueued) {
try {
if (numFilesQueued > ) {
/* var v = $("#mes").html();
var str = "触发fileDialogComplete事件,参数numFilesSelected:" + numFilesSelected + ",参数numFilesQueued:" + numFilesQueued;
$("#mes").html(v + str + "<br />");*/
this.startUpload();
}
} catch (ex) {
this.debug(ex);
}
}
function uploadProgress(file, bytesLoaded) {
try {
var percent = Math.ceil((bytesLoaded / file.size) * ); // 计算百分比
$("#filename").html(file.name);
$("#filesize").html(file.size);
$("#ysc").html(bytesLoaded);
$("#bfb").html(percent);
/* var v = $("#mes").html();
var str = "触发uploadProgress事件,参数file:" + file + ",参数bytesLoaded:" + bytesLoaded;
$("#mes").html(v + str + "<br />");*/
} catch (ex) {
this.debug(ex);
}
}
function uploadSuccess(file, serverData) {
try {
/* var v = $("#mes").html();
var str = "触发uploadSuccess事件,参数file:" + file + ",参数serverData:" + serverData;
$("#mes").html(v + str + "<br />");*/
} catch (ex) {
this.debug(ex);
}
}
function uploadComplete(file) {
try {
/* I want the next upload to continue automatically so I'll call startUpload here */
if (this.getStats().files_queued > ) {
this.startUpload();
}
var v = $("#mes").html();
var str = "触发uploadComplete事件,参数file:" + file+",<span style='color:red;font-weight:bold;'>文件"+file.name+"上传完成</span>";
$("#mes").html(v + str + "<br />");
} catch (ex) {
this.debug(ex);
}
}
function uploadError(file, errorCode, message) {
try {
switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
try {
}
catch (ex1) {
this.debug(ex1);
}
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
try {
}
catch (ex2) {
this.debug(ex2);
}
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
break;
default:
alert(message);
break;
}
var v = $("#mes").html();
var str = "触发uploadError事件,参数file:" + file + ",参数errorCode:" + errorCode + ",参数message:" + message;
$("#mes").html(v + str + "<br />");
} catch (ex3) {
this.debug(ex3);
}
}
</script>
<script type="text/javascript">
var swfu;
window.onload = function() {
swfu = new SWFUpload({
// 基本设置
upload_url: "upload.aspx",
post_params: {
"ASPSESSID": "<%=Session.SessionID %>"
},
// 上传文件设置
file_size_limit: "100 MB",
file_types: "*.jpg;*.avi;*.rar;*.mp4",
file_types_description: "支持上传的格式",
file_upload_limit: "", // 0表示不限制选择文件的数量
// 定义事件
file_queue_error_handler: fileQueueError,
file_dialog_complete_handler: fileDialogComplete,
upload_progress_handler: uploadProgress,
upload_error_handler: uploadError,
upload_success_handler: uploadSuccess,
upload_complete_handler: uploadComplete,
// 按钮设置
button_image_url: "images/XPButtonNoText_160x22.png",
button_placeholder_id: "spanButtonPlaceholder",
button_width: ,
button_height: ,
button_text: '<span class="button">选择文件 <span class="buttonSmall">(最大 100 MB)</span></span>',
button_text_style: '.button { font-family: 微软雅黑, sans-serif; font-size: 14pt; } .buttonSmall { font-size: 12pt; }',
button_text_top_padding: ,
button_text_left_padding: ,
// Flash设置
flash_url: "swfupload/swfupload.swf",
// 是否开启调试,true是,false否
debug: false
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h1>
SWFUpload上传大文件</h1>
<div id="swfu_container" style="margin: 0px 10px;">
<div>
<span id="spanButtonPlaceholder"></span>
</div>
<div style="height: 75px;">
文件名称:<span id="filename"></span><br />
文件大小:<span id="filesize"></span> 字节<br />
已上传:<span id="ysc"></span> 字节<br />
上传百分比:<span id="bfb"></span>%
</div>
</div>
<hr />
<div id="mes">
</div>
</form>
</body>
</html>