一、上傳按鈕樣式
1.1id="show_filebutton"是顯示給使用者操作按鈕,id="filebutton"是flash上傳按鈕完成使用者上傳操作。id="show_filebutton"按鈕樣式不需要變,隻需要将id="filebutton"按鈕覆寫在id="show_filebutton"按鈕上面就行了。
1.2uploadify會生成自己的html元素class="swfupload"
<html>
<body>
<head>
<style>
.swfupload{background:red;} //設定flash上傳按鈕背景顔色。可以看到按鈕友善設定寬高等css屬性
.swfupload{width: 120px;height: 35px; top: -35px;left: 50px;opacity:0;} //flash上傳按鈕覆寫美工提供過來的上傳按鈕,uploadify上傳按鈕本身就是透明不可見,這樣友善我們覆寫在按鈕上面達到效果
</style>
</head>
<button id="show_filebutton" type="button">導入資料檔案</button>
<button type="button" id="filebutton"></button>
</body>
</html>
二、綁定上傳按鈕事件
$(document).ready(function(){
$("#filebutton").uploadify({
'swf' : '/plugin/uploader/uploadify.swf',
'uploader' : '/simple/upload.do',
'buttonclass' : 'upload',
'buttontext' : '',
'width': 'auto',
'queueid' : "upload_queue",
'auto' : false,
'fileobjname' : 'uploads',
'multi' : false, //多檔案上傳
'filesizelimit' : 2048 , //限制檔案的大小,預設機關是kb
'uploadlimit' : 1,
'filetypedesc' : '支援資源格式:',
'filetypeexts' : '*.xls;*.xlsx;',
'onuploadstart' : function(file){
$('#filebutton').uploadify("settings", "formdata", {para:1});
},
'onuploadsuccess' : function(file, data, response) {
var uploadlimit = $("#filebutton").uploadify('settings', 'uploadlimit'); //get
$("#filebutton").uploadify('settings', 'uploadlimit', uploadlimit+1); //set
$("#downloadfilename").val(data);
}
});
java上傳代碼
public class upload(){
public void uploadimage(){
uuid uuid = uuid.randomuuid();
string syspath = getsession().getservletcontext().getrealpath("");
file tempfile = new file(syspath+"/upload/temp/");
if(!tempfile.exists()){
tempfile.mkdirs();
uploadfile upfile = getfile("image");
if(upfile != null){
file file = upfile.getfile();
string filename = uuid+"_"+file.getname();
string filepath = "/upload/temp/"+filename;
file.renameto(new file(syspath+filepath));
setattr("filepath", filepath);
renderjson();
感謝您的閱讀,您的支援是我寫部落格動力。