<table>
<tr>
<td>文件</td>
<td>
<div id="progressTarget"></div>
<div>
<span id="buttonPlaceholderId"></span>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<button type="button" οnclick="doSwfUpload()">上传</button>
<button type="button" οnclick="hide('swfUpload')">返回</button>
</td>
</tr>
</table>
var upload;
window.onload = function() {
upload = new SWFUpload({
//处理文件上传的url
upload_url: "${pageContext.request.contextPath}/file/commonsFileUpload.html",
flash_url : "<%=request.getContextPath()%>/js/swfupload_fp10/swfupload.swf",
//上传文件限制设置
file_size_limit : "10240",
file_upload_limit : "0",
file_queue_limit : "2",
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
button_placeholder_id : "buttonPlaceholderId",
button_width : 61,
button_height : 22,
button_text : "选择文件",
button_cursor : SWFUpload.CURSOR.HAND,
custom_settings : {
progressTarget : "progressTarget"
},
debug: false
});
function uploadStart(){
console.log("上传开始");
}
function uploadProgress(){
console.log("上传处理中...");
}
function uploadError(){
console.log("上传出错");
}
function uploadSuccess(){
console.log("上传成功");
}
function uploadComplete(){
console.log("上传完成");
}
};
function doSwfUpload(){
upload.startUpload();
}
不太会用,api提供挺多方法和事件,自定义的多,界面没想像中炫,可能要自己设计,多选上传,后台只读到一个文件,不知道哪里设置错了,它不用定义form,直接触发startUpload()方法即可开始上传。需要单独配置url。进度条,暂停,取消等功能要单独设计,有点底层了。除非真的上传大文件,不然不会设置这么底层的。