DIV CSS 佈局教程網

Uploadify 3.0 完整設定說明:屬性與事件對照
編輯:JQuery特效代碼     

Uploadify 是以 Flash 為底層的 jQuery 多檔上傳外掛,設定項目相當多。以下把它的屬性與事件整理成可對照的清單。

一、基本用法

// 綁定的介面元素:<input id="gallery" type="file" />
$("#gallery").uploadify({
  // 設定參數
});

二、屬性

{
  id: jQuery(this).attr('id'),   // 綁定的 input ID

  langFile: '.../uploadifyLang_en.js',  // 語言包路徑,可一次改寫所有提示文字
  swf:      '.../uploadify.swf',        // [必填] swf 路徑
  uploader: '/uploadify/galleri.php',   // [必填] 上傳觸發的 URL

  auto:        false,             // 選檔完成後是否自動上傳
  buttonText:  'Välj Filer',      // 上傳按鈕文字
  height:      30,                // 按鈕高度
  width:       120,               // 按鈕寬度
  buttonCursor:'pointer',         // 滑鼠移入的游標樣式

  cancelImage: '/upload/xxx.png',  // [必填] 取消圖示路徑
  checkExisting: '/uploader/uploadify-check-existing.php', // 檢查檔名是否已存在,回傳 1/0
  debug: true,                     // 除錯模式,開啟後會輸出除錯訊息

  fileObjName:    'file',          // 上傳時的欄位名稱
  fileSizeLimit:  0,               // 單檔大小上限(位元組),0 表示不限制;1MB = 1*1024*1024
  fileTypeDesc:   'Bild JPG',      // 檔案選擇框中顯示的類型描述
  fileTypeExts:   '*.jpg',         // 允許的副檔名

  method:   'post',                // 與後端互動方式:post / get
  multi:    true,                  // 是否可多選
  queueID:  'fileQueue',           // 顯示佇列的容器 id
  queueSizeLimit: 999,             // 佇列中允許的最大檔案數

  progressData: 'all',             // 'percentage' 百分比 / 'speed' 速度 / 'all' 兩者
  removeCompleted: true,           // 上傳成功後是否自動移出佇列
  removeTimeout:   3,
  requeueErrors:   true,           // 出錯檔案是否自動重排
  postData: {},                    // 附加的 POST 參數
  preventCaching: true,
  transparent:    true,
  successTimeout: 30,              // 上傳 timeout(秒)
  uploadLimit:    999              // 可同時上傳的檔案數
}

三、事件

onDialogOpen / onDialogClose

檔案選擇對話框開啟與關閉時觸發。onDialogClose 的參數可取得本次選擇的統計資訊:

onDialogClose: function (queue) {
  if (queue.filesErrored > 0) {
    alert('加入佇列時有 ' + queue.filesErrored + ' 個檔案發生錯誤\n' +
          '錯誤訊息: '   + queue.errorMsg      + '\n' +
          '選定的檔案數: ' + queue.filesSelected + '\n' +
          '成功加入佇列的檔案數: ' + queue.filesQueued + '\n' +
          '佇列中的總檔案數: '     + queue.queueLength);
  }
},
onDialogOpen: function () {
  alert('Open!');
}

onSelect / onSelectError

onSelect: function (file) {
  // file.id / index / name / size / type
  // file.creationdate / modificationdate / filestatus
},
onSelectError: function (file, errorCode, errorMsg) {
  // 額外帶 errorCode 與 errorMsg
}

onQueueComplete

onQueueComplete: function (stats) {
  // stats.successful_uploads / upload_errors / upload_cancelled / queue_errors
}

onUploadStart / onUploadSuccess / onUploadComplete / onUploadError / onUploadProgress

onUploadStart: function (file) { /* 每個檔案開始上傳時觸發一次 */ },

onUploadSuccess: function (file, data, response) {
  // data 為後端回應內容,response 代表是否成功
},

onUploadComplete: function (file, queue) { /* 每個檔案上傳完成時觸發 */ },

onUploadError: function (file, errorCode, errorMsg, errorString, queue) {
  // errorMsg 為詳細描述,errorString 為簡要描述
},

onUploadProgress: function (file, fileBytesLoaded, fileTotalBytes,
                            queueBytesLoaded, queueSize) {
  // 可用來更新進度條
}

四、實務提醒

  • Uploadify 3.x 依賴 Flash,因此無法在 iOS/Android 等非 Flash 平台上運作。若專案需要跨裝置,建議改用 HTML5 方案(如 <input type="file" multiple> 搭配 XMLHttpRequest 的 FormData,或 jQuery-File-Upload、Plupload 等外掛)。
  • 近年的主流瀏覽器已全面停止支援 Flash,Flash 於 2020 年底正式終止服務,本外掛僅適合維護既有舊系統時參考。
  • swf 與 cancelImage 為必填,缺少任一項外掛無法正常初始化。
  • 後端回傳的字串會原封不動進到 onUploadSuccess 的 data,因此約定好成功/失敗的判定字串(例如以特定前綴開頭)會讓前端判斷更直觀。
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved