使用:
複製代碼 代碼如下:
//綁定的介面元素<input id='gallery'type='file'/>
$("#gallery").uploadify({
設定參數,參數如下.
});
設定的屬性:
複製代碼 代碼如下:
id: jQuery(this).attr('id'),//綁定的input的ID
langFile: 'http://www.static-xxx.nu/uploader/uploadifyLang_en.js',//語言套件的路徑,能設定所有的提示文字
swf: 'http://www.static-xxx.nu/uploader/uploadify.swf',//[必須設定]swf的路徑
uploader: '/uploadify/galleri.php',//[必須設定]上傳檔案觸發的url
auto:false,//檔案選擇完成後,是否自動上傳
buttonText:'Välj Filer',//上傳按鈕的文字
height: 30,//上傳按鈕的高和寬
width: 120,
buttonCursor: 'pointer',//上傳滑鼠hover後Cursor的形狀
cancelImage: '/upload/201206/20120618142325932.png',//[必須設定]取消圖片的路徑
checkExisting:'/uploader/uploadify-check-existing.php',//檢查上傳檔案是否存,觸發的url,返回1/0
debug: true,//debug模式開/關,開啟後會顯示debug時的資訊
fileObjName:'file',
fileSizeLimit : 0,//檔案的極限大小,以位元組為單位,0為不限制。1MB:1*1024*1024
fileTypeDesc: 'Bild JPG',//允許上傳的檔案類型的描述,在彈出的檔案選擇框裡會顯示
fileTypeExts: '*.jpg',//允許上傳的檔案類型,限制彈出檔案選擇框裡能選擇的檔案
method: 'post',//和後台互動的方式:post/get
multi: true,//是否能選擇多個檔案
queueID: 'fileQueue',//顯示上傳檔案隊列的元素id,可以簡單用一個div來顯示
queueSizeLimit : 999,//隊列中允許的最大檔案數目
progressData : 'all', // 'percentage''speed''all'//隊列中顯示檔案上傳進度的方式:all-上傳速度+百分比,percentage-百分比,speed-上傳速度
removeCompleted : true,//上傳成功後的檔案,是否在隊列中自動刪除
removeTimeout: 3,
requeueErrors : true,
postData: {},//和後台互動時,附加的參數
preventCaching : true,
transparent: true,
successTimeout : 30,//上傳時的timeout
uploadLimit:999//能同時上傳的檔案數目
設定的事件:
複製代碼 代碼如下:
onDialogClose : function(swfuploadifyQueue) {//當檔案選擇對話方塊關閉時觸發
if( swfuploadifyQueue.filesErrored > 0 ){
alert( '添加至隊列時有'
+swfuploadifyQueue.filesErrored
+'個檔案發生錯誤n'
+'錯誤資訊:'
+swfuploadifyQueue.errorMsg
+'n選定的檔案數:'
+swfuploadifyQueue.filesSelected
+'n成功添加至隊列的檔案數:'
+swfuploadifyQueue.filesQueued
+'n隊列中的總檔案數量:'
+swfuploadifyQueue.queueLength);
}
}
onDialogOpen : function() {//當選擇檔案對話方塊開啟時觸發
alert( 'Open!');
}
onSelect : function(file) {//當每個檔案添加至隊列後觸發
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 檔案名稱: ' + file.name
+ ' - 檔案大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 建立日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 檔案狀態: ' + file.filestatus);
}
onSelectError : function(file,errorCode,errorMsg) {//當檔案選定發生錯誤時觸發
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 檔案名稱: ' + file.name
+ ' - 檔案大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 建立日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 檔案狀態: ' + file.filestatus
+ ' - 錯誤碼: ' + errorCode
+ ' - 錯誤資訊: ' + errorMsg);
}
onQueueComplete : function(stats) {//當隊列中的所有檔案全部完成上傳時觸發
alert( '成功上傳的檔案數: ' + stats.successful_uploads
+ ' - 上傳出錯的檔案數: ' + stats.upload_errors
+ ' - 取消上傳的檔案數: ' + stats.upload_cancelled
+ ' - 出錯的檔案數' + stats.queue_errors);
}
onUploadComplete : function(file,swfuploadifyQueue) {//隊列中的每個檔案上傳完成時觸發一次
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 檔案名稱: ' + file.name
+ ' - 檔案大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 建立日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 檔案狀態: ' + file.filestatus
+ ' - 出錯的檔案數: ' + swfuploadifyQueue.filesErrored
+ ' - 錯誤資訊: ' + swfuploadifyQueue.errorMsg
+ ' - 要添加至隊列的數量: ' + swfuploadifyQueue.filesSelected
+ ' - 添加至對立的數量: ' + swfuploadifyQueue.filesQueued
+ ' - 隊列長度: ' + swfuploadifyQueue.queueLength);
}
onUploadError : function(file,errorCode,errorMsg,errorString,swfuploadifyQueue) {//上傳檔案出錯是觸發(每個出錯檔案觸發一次)
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 檔案名稱: ' + file.name
+ ' - 檔案大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 建立日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 檔案狀態: ' + file.filestatus
+ ' - 錯誤碼: ' + errorCode
+ ' - 錯誤描述: ' + errorMsg
+ ' - 簡要錯誤描述: ' + errorString
+ ' - 出錯的檔案數: ' + swfuploadifyQueue.filesErrored
+ ' - 錯誤資訊: ' + swfuploadifyQueue.errorMsg
+ ' - 要添加至隊列的數量: ' + swfuploadifyQueue.filesSelected
+ ' - 添加至對立的數量: ' + swfuploadifyQueue.filesQueued
+ ' - 隊列長度: ' + swfuploadifyQueue.queueLength);
}
onUploadProgress : function(file,fileBytesLoaded,fileTotalBytes,
queueBytesLoaded,swfuploadifyQueueUploadSize) {//上傳進度發生變更時觸發
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 檔案名稱: ' + file.name
+ ' - 檔案大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 建立日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 檔案狀態: ' + file.filestatus
+ ' - 當前檔案已上傳: ' + fileBytesLoaded
+ ' - 當前檔案大小: ' + fileTotalBytes
+ ' - 隊列已上傳: ' + queueBytesLoaded
+ ' - 隊列大小: ' + swfuploadifyQueueUploadSize);
}
onUploadStart: function(file) {//上傳開始時觸發(每個檔案觸發一次)
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 檔案名稱: ' + file.name
+ ' - 檔案大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 建立日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 檔案狀態: ' + file.filestatus );
}
onUploadSuccess : function(file,data,response) {//上傳完成時觸發(每個檔案觸發一次)
alert( 'id: ' + file.id
+ ' - 索引: ' + file.index
+ ' - 檔案名稱: ' + file.name
+ ' - 檔案大小: ' + file.size
+ ' - 類型: ' + file.type
+ ' - 建立日期: ' + file.creationdate
+ ' - 修改日期: ' + file.modificationdate
+ ' - 檔案狀態: ' + file.filestatus
+ ' - 伺服器端訊息: ' + data
+ ' - 是否上傳成功: ' + response);
}