SWFUpload V2.2.0 API 說明文檔
TOC
- SWFUpload
- SWFUpload 2
- 概述
- 入門
- SWFUpload JavaScript 對象
- 構造器
- 全局變量和常量
- 屬性
- 方法
- addSetting (不推薦使用)
- getSetting (不推薦使用)
- retrieveSetting (v2.1.0中已刪除)
- destroy (v2.1.0中新增)
- displayDebugInfo
- selectFile (不推薦使用)
- selectFiles (不推薦使用)
- startUpload
- cancelUpload
- stopUpload
- getStats
- setStats
- getFile
- addPostParam
- removePostParam
- addFileParam
- removeFileParam
- setUploadURL
- setPostParams
- setFileTypes
- setFileSizeLimit
- setFileUploadLimit
- setFileQueueLimit
- setFilePostName
- setUseQueryString
- setDebugEnabled
- setButtonImageURL (added in v2.2.0)
- setButtonDimensions (added in v2.2.0)
- setButtonText (added in v2.2.0)
- setButtonTextStyle (added in v2.2.0)
- setButtonTextPadding (added in v2.2.0)
- setButtonDisabled (added in v2.2.0)
- setButtonAction (added in v2.2.0)
- setButtonCursor (added in v2.2.0)
- 事件
- SWFUpload 功能對象
- SWFUpload 插件(未譯)
- 存在的問題(未譯)
SWFUpload
SWFUpload最初是由Vinterwebb.se開發的一個客戶端的上傳工具. 它結合了FLASH和JavaScript的功能,以提供一種超越了傳統的瀏覽器中<input type="file" />標簽提供的文件上傳功能。
SWFUpload提供的主要功能:
- 在文件選擇對話框中能夠進行文件多選
- 頁面無刷新的上傳
- 提供上傳進度的事件回調,實時顯示上傳進度
- 良好的瀏覽器兼容性
- 采用了命名空間以兼容其它JS的庫 (例如 jQuery, Prototype, 等等)
對FLASH 8和FLASH 9播放器的支持- 對FLASH 9和FLASH 10播放器的支持(V2.2.0版本放棄了對Flash 8的支持)
SWFUpload背后的設計思想和其它基於Flash的上傳工具是不同的。它將瀏覽器的中UI交給開發人員來控制。開發人員能夠利用XHTML,CSS,Javascript來定制符合他們網站風格的UI上傳元素。然后使用它提供的一組簡單的JS事件來更新上傳狀態,開發人員能夠利用這些事件來及時更新頁面中的上傳進度UI。
不幸的是Flash Player 10 更嚴格的安全機制迫使我們不得不將一個Flash Button放入Flash影片中。SWFUpload提供API供開發者通過圖片、文字、CSS的方式來自定制更靈活的UI顯示。
SWFUpload v2
SWFUpload v2包含了新的高級功能,改善了穩定性,解決了FlashPlayer中的一些bug,並且提供一套有用的插件。新的功能包括:
- 兼容了Flash Player 10的安全限制問題
- 在文件上傳的同時能夠發送額外的POST數據
- 針對每一個文件上傳發送POST/GET數據
- 更直觀的事件回調
- 動態修改實例設置
- 接收服務端返回的數據
- 非取消形式的停止文件上傳
- 自定義上傳的順序
- 支持單文件、多文件的文件的選擇
- 文件入隊數量,文件上傳數量和文件大小的限制
- 更合理地處理0字節的文件
- 針對每個文件在上傳前都提供一個最后確認的時間回調
- 解決了v1.0.2版本中未描述到的關於Flash的bug
- 解決的v1.0.2中的bug:
- 在IE中,刷新的時候FLASH無法加載(詳細可見我之前的debug過程)
- 在FireFox中,如果窗口的滾動條沒有回滾到頂部,那么Flash無法加載
- Race-conditions when files are cached
- 兼容ASP.Net Forms
SWFUpload v2 延續了SWFUpload的設計目標,將UI分離以交給開發人員控制和后續擴展
概述
傳統的HTML上傳
標准的HTML上傳表單為用戶提供一個文本框和按鈕來選擇文件,選中的文件是隨着form表單提交的。整個文件上傳完成之后,下一個頁面才會顯示,並且不能對選擇的文件做預設的文件檢驗,例如文件大小限制,文件類型限制。當文件上傳時,用戶獲得的可用的反饋信息很少。
傳統的HTML上傳模式十分簡單,線性的,幾乎所有瀏覽器都支持它。
SWFUpload
SWFUpload使用一個隱藏的Flash影片來控制文件的選擇和上傳。JavaScript用來激活文件選擇對話框。 此文件選擇對話框是可以設置允許用戶選擇一個單獨的文件或者是多個文件。
SWFUpload使用一個Flash影片來控制文件的選擇和上傳。此FLASH中包含一個用戶自定制UI的按鈕,點擊該按鈕能夠激活Flash本身的高級文件上傳對話框,它能夠根據用戶的設置來進行單文件或者是多文件的上傳。 選擇的的文件類型也是可以被限制的,因此用戶只能選擇指定的適當的文件,例如*.jgp;*.gif。
提醒:Flash Player 10的安全機制更嚴格,類似打開文件上傳的對話框的操作,一定需要用戶交互才觸發,如果用腳本觸發,會報#2176的運行時錯誤。因此V2.2.0版本在SWF中添加了一個可定制的Button讓用戶交互來打開文件對話框。
當選定文件以后,每個文件都會被驗證和處理。當Flash上傳文件的時候,由開發人員預定義的Javascript事件會被定時觸發以便來更新頁面中的UI,同時還提供上傳狀態和錯誤信息。
選定的文件的上傳和它所在頁面、表單是獨立的。每個文件都是單獨上傳的,這就保證了服務端腳本能夠在一個時間點更容易地處理單個文件。雖然Flash提供了上傳服務,但是頁面並不會提交或者重新載入。相比於標准的HTML Form,SWFUpload的使用方式更像是AJAX程序,頁面中的Form會和FLASH控制的文件上傳單獨處理。
入門
SWFUpload並不是拖放式的上傳控件,它需要JavaScript和DOM的知識。一些可用的演示展示了它能夠完成什么事情以及它是如何完成這些常見的任務。
SWFUpload由4部分組成:
- 初始化和設置(Javascript)
- JavaScript 庫: SWFUpload.js
Flash控制元素: SWFUpload_f8.swf 或者 SWFupload_f9.swfSWFUpload.swf(V2.2.0版本放棄了對flash 8的支持)- 事件處理(Javascript)
使用SWFUpload遇到的多數問題是由不正確地設置或者定義了糟糕的處理事件引起的。
初始化和設置
SWFpload必須在頁面中初始化,一般可以在window.onload事件中完成此操作。它的構造函數需要一個Object類型的設置對象。 這個設置對象一般是一個直接定義的Object類型變量,直接傳遞給SWFUpload的構造函數。
初始化的SWFUpload對象的引用需要保留下來,因為當顯示文件選擇對話框和啟動文件上傳的時候需要這個實例的引用。
例如:用直接定義的Object類型變量設置初始化SWFUpload對象
var swfu; window.onload = function () { swfu = new SWFUpload({ upload_url : "http://www.swfupload.org/upload.php", flash_url : "http://www.swfupload.org/swfupload.swf", button_placeholder_id : "spanSWFUploadButton", file_size_limit : "20480" }); };
例如:用存儲在變量中的設置對象初始化SWFUpload對象
var swfu; window.onload = function () { var settings_object = { upload_url : "http://www.swfupload.org/upload.php", flash_url : "http://www.swfupload.org/swfupload.swf", button_placeholder_id : "spanSWFUploadButton", file_size_limit : "20480" }; swfu = new SWFUpload(settings_object); };
JavaScript 庫
該JavaScript庫文件(swfupload.js)應該包含在需要上傳功能的頁面中。
當SWFUpload創建完成並能訪問它的一系列功能時,開發人員可以來控制此實例。
例如: 添加SWFUpload.js到頁面中
<script type="text/javascript" src="http://www.swfupload.org/swfupload.js"></script>
例如: 根據需要的設置來初始化SWFUpload,同時把它的seleteFiles方法綁定到一個按鈕的Click事件上。
var swfu = new SWFUpload({ upload_url : "http://www.swfupload.org/upload.php", flash_url : "http://www.swfupload.org/swfupload.swf", button_placeholder_id : "spanSWFUploadButton" });document.getElementById("BrowseButton").onclick = function () { swfu.selectFiles(); };
Flash 控制元素
SWFUpload JavaScript庫動態加載Flash控制元素(swfupload.swf)。該Flash控制元素有兩個版本。swfupload_f8.swf支持Flash Player8以及更高版本。它在提供了更好的兼容性同時犧牲了一些功能。swfupload_f9.swf支持Flash Player9.0.28以及更高版本。它在提供了額外的功能同時犧牲了使用Flash Player8的用戶。
Flash控制元素的文件地址在初始化的時候就應該在SWFUpload設置對象中定義。
Flash控制元素是一個很小的的Flash影片,它提供了文件瀏覽、檢驗和上傳功能。它在頁面中展現給用戶的是一個UI可自定制的按鈕,但該Flash會在需要時候通過與Javascript通信來通知瀏覽器處理更新。
事件處理
開發人員必須定義一系列JavaScript函數來處理SWFUpload事件回調,當一些不同的重要事件發生的時候,這些函數會被觸發。
通過處理SWFUpload的事件,開發人員能夠提供關於上傳進度、出錯信息以及上傳完成等的信息反饋。
例如: swfupload的處理事件和初始化
// uploadStart處理事件。該函數變量在設置對象中指定給了upload_start_handler屬性。 var uploadStartEventHandler = function (file) { var continue_with_upload; if (file.name === "the sky is blue") { continue_with_upload = true; } else { continue_with_upload = false; } return continue_with_upload; }; //uploadSuccess處理事件。 該函數變量在設置對象中指定給了upload_success_handler屬性。 var uploadSuccessEventHandler = function (file, server_data) { alert("The file " + file.name + " has been delivered to the server."); alert("The server responded with " + server_data); }; //創建SWFUpload實例,設置事件回調函數 var swfu = new SWFUpload({ upload_url : "http://www.swfupload.org/upload.php", flash_url : "http://www.swfupload.org/swfupload.swf", file_size_limit : "20480", upload_start_handler : uploadStartEventHandler, upload_success_handler : uploadSuccessEventHandler });
SWFUpload JavaScript 對象
構造函數
SWFUpload(settings object)
返回:一個SWFUpload 實例
var swfupload_instance = new SWFUpload(settings_object);
全局變量和常量
SWFUpload定義了一些全局變量和常量,這對SWFUpload的高級應用程序和處理錯誤都是很有用的,它們都是只讀的。
SWFUpload.instances
SWFUpload.instances是一個存儲了頁面中所有SWFUpload實例引用的數組。Flash播放器依靠這個數組來調用正確的處理事件。該數組是由movieName屬性來索引的關聯數組。例如:SWFUpload.instances.SWFUpload_0訪問的是第一個實例引用。
注意: SWFUpload.instances不是一個真正的JavaScript數組,實際上它是一個對象(關聯數組)。
SWFUpload.movieCount
SWFUpoad.movieCount是一個全局變量,用於記錄頁面中的SWFUpload實例個數,同時確保給每一個Flash影片分配一個惟一的movieName。
SWFUpload.QUEUE_ERROR
SWFUpload.QUEUE_ERROR是一個包含了Queue Error錯誤碼的JS對象,一般用它來查看fileQueueError事件的中發送的錯誤碼,以確定fileQueueError的具體類型。
SWFUpload.QUEUE_ERROR = { QUEUE_LIMIT_EXCEEDED : -100, FILE_EXCEEDS_SIZE_LIMIT : -110, ZERO_BYTE_FILE : -120, INVALID_FILETYPE : -130 };
SWFUpload.UPLOAD_ERROR
SWFUpload.UPLOAD_ERROR是一個包含了Upload Error錯誤碼的JS對象,一般用它來查看uploadError事件的中發送的錯誤碼,以確定uploadError的具體類型。
SWFUpload.UPLOAD_ERROR = { HTTP_ERROR : -200, MISSING_UPLOAD_URL : -210, IO_ERROR : -220, SECURITY_ERROR : -230, UPLOAD_LIMIT_EXCEEDED : -240, UPLOAD_FAILED : -250, SPECIFIED_FILE_ID_NOT_FOUND : -260, FILE_VALIDATION_FAILED : -270, FILE_CANCELLED : -280, UPLOAD_STOPPED : -290 };
SWFUpload.FILE_STATUS
SWFUpload.FILE_STATUS是一個包含File Status狀態碼的JS對象。它可以用來檢測File對象中的file status屬性,以確定文件的狀態。
SWFUpload.FILE_STATUS = { QUEUED : -1, IN_PROGRESS : -2, ERROR : -3, SUCCESS : -4, CANCELLED : -5 };
默認處理事件
SWFUpload庫提供了一系列默認的處理事件。當開發人員沒有自定義處理事件時,SWFUpload庫將調用這些默認的處理事件。因此當自定義事件時,不要把這些默認的處理事件覆蓋了。自定義事件是需要在settings對象中被單獨定義的。
SWFUpload.BUTTON_ACTION
SWFUpload.BUTTON_ACTION是一個包含button的動作預設的JS對象。
SWFUpload.BUTTON_ACTION = { SELECT_FILE : -100, SELECT_FILES : -110, START_UPLOAD : -120 }
可以使用button_action屬性來設置Flash本身的文件上傳對話框的行為。默認為SWFUpload.BUTTON_ACTION.SELECT_FILES,點擊按鈕將會打開多文件上傳的對話框。如果設置為SWFUpload.BUTTON_ACTION.SELECT_FILE,則為單文件上傳。如果設置為SWFUpload.BUTTON_ACTION.START_UPLOAD,則啟動文件上傳
SWFUpload.CURSOR
SWFUpload.CURSOR是一個包含button的光標狀態碼的JS對象。
SWFUpload.CURSOR = { ARROW : -1, HAND : -2 }
可以使用button_cursor屬性來設置鼠標划過button時的光標狀態。默認為SWFUpload.CURSOR.ARROW,如果設置為SWFUpload.CURSOR.HAND,則為手形
SWFUpload.WINDOW_MODE
SWFUpload.WINDOW_MODE是一個包含了該SWF插入到頁面中的wmode屬性的JS對象.可以通過設置button_window_mode屬性來告訴瀏覽器具體以哪種模式顯示此SWF。
SWFUpload.WINDOW_MODE = { WINDOW : "window", TRANSPARENT : "transparent", OPAQUE : "opaque" };
SWFUpload.WINDOW_MODE.WINDOW是默認的模式. 該SWF將位於頁面元素的最高層級。
SWFUpload.WINDOW_MODE.OPAQUE 該SWF可以被頁面類的其他元素通過層級的設置來覆蓋它。
SWFUpload.WINDOW_MODE.TRANSPARENT 該SWF的背景是透明的,可以透過它看到背后的頁面元素。
屬性
下面這個列表是相關屬性的具體描述。使用其它屬性或者對只讀屬性進行了寫的操作都會造成SWFUpload出現問題。
customSettings (可讀/可寫)
customSettings屬性是一個空的JavaScript對象,它被用來存儲跟SWFUpload實例相關聯的數據。它的內容可以使用設置對象中的custom_settings屬性來初始化。
注意:一些插件使用customSettings對象來實現它們的內部控制。當重寫整個customSettings對象的時候需要務必小心。
例如:
// 初始化包含自定義設置的SWFUpload對象 var swfu = new SWFUpload({ custom_settings : { custom_setting_1 : "custom_setting_value_1", custom_setting_2 : "custom_setting_value_2", custom_setting_n : "custom_setting_value_n", } }); swfu.customSettings.custom_setting_1 = "custom_setting_value_1"; // 更改一個存在的自定義設置 swfu.customSettings.myNewCustomSetting = "new custom setting value"; // 添加一個新的自定義設置 //用一個全新的對象重寫customSettings swfu.customSettings = { custom_setting_A : "custom_setting_value_A", custom_setting_B : "custom_setting_value_B" };
movieName(只讀)
包含了該SWFUpload實例的惟一影片名字。該值被傳遞給Flash,用來完成Flash和JavaScript的通信。該值被用來索引實例在SWFUpload.instances數組中的位置,你無法更改此值。
方法
下面的方法用來操作SWFUpload。其中有些方法可以跟元素(例如,按鈕)的點擊事件綁定,其它的方法供SWFUpload內部處理事件中調用。
object addSetting(setting_name, value, default_value)
不贊成使用 V2.1.0源碼中注釋:addSetting和getSetting已經不再被使用了,只是考慮到兼容V2版本,才繼續保留在庫中。
object getSetting(setting_name)
不贊成使用 V2.1.0源碼中注釋:addSetting和getSetting已經不再被使用了,只是考慮到兼容V2版本,才繼續保留在庫中。
object retrieveSetting(setting_value, default_value)
v2.1.0中已被刪除
bool destroy()
v2.1.0中新增
用於將一個SWFUpload實例從頁面中銷毀。不但刪除DOM中的Flash元素,同時還刪除SWFUpload實例的相關引用。成功返回true,失敗返回false。
這個方法還沒有針對插件做兼容測試,可能會有不兼容問題。(尤其是SWFObject插件)
提醒:SWFUpload在v2.1.0中改寫了Flash插入的代碼,V2版中使用SWFObject插入Flash會造成IE的一個刷新BUG。
void displayDebugInfo()
調用debug方法,在Debug輸出框中顯示SWFUpload實例的設置信息,如果設置中的debug屬性是true,那么默認是在實例化完成以后自動調用此方法。
void selectFile()
不贊成使用,不兼容Flash Player 10
彈出flash的文件選擇對話框,只能選擇單個文件。
提醒:Flash Player 10的安全機制更嚴格,類似打開文件上傳的對話框的操作,一定需要用戶交互才觸發,如果用腳本觸發,會報#2176的運行時錯誤。因此V2.2.0版本在SWF中添加了一個可定制的Button讓用戶交互來打開文件對話框。
void selectFiles()
不贊成使用,不兼容Flash Player 10
彈出flash的文件選擇對話框,可一次性選擇多個文件。
提醒:Flash Player 10的安全機制更嚴格,類似打開文件上傳的對話框的操作,一定需要用戶交互才觸發,如果用腳本觸發,會報#2176的運行時錯誤。因此V2.2.0版本在SWF中添加了一個可定制的Button讓用戶交互來打開文件對話框。
void startUpload(file_id)
指定file_id來啟動該文件的上傳,如果file_id被忽略了,那么默認開始上傳第一個文件。
void cancelUpload(file_id, trigger_error_event)
指定file_id來退出文件的上傳,從上傳隊列中刪除該文件。
如果忽略file_id,那么默認文件上傳隊列中的第一個文件將被退出上傳。
如果取消的文件是正在上傳,那么會觸發uploadError事件。
如果將可選參數trigger_error_event設置為false,那么uploadError事件不會觸發。
void stopUpload()
如果當前有文件上傳,那么停止上傳,並且將文件還原到上傳隊列中。
停止了正在上傳的文件,uploadError事件會被觸發。如果此時沒有正在上傳文件,那么不會發生任何操作,不會觸發任何事件。
object getStats()
獲取當前狀態的統計對象,具體見Stats Object。
void setStats(stats_object)
Stats統計對象是可以被修改的。如果你希望在上傳完畢之后修改上傳成功或者上傳失敗的統計數目時,那么可以使用該方法。
提醒:可供修改的屬性只有successful_uploads ,upload_errors,upload_cancelled,queue_errors,並且值必須是Number類型。
object getFile(file_id|index)
根據file_id或者index來獲取文件隊列中的文件對象。file_id是文件對象中的id屬性,index是文件對象中的index屬性。
傳遞Number類型的參數會被認定為index,那么返回的是文件隊列(所有嘗試入隊文件,包括因沒有通過文件大小、類型檢測等而觸發fileQueueError,沒有成功加入文件上傳隊列的文件對象)數組中下標為index的文件對象。如果index不在隊列數組范圍內,那么返回null。
傳遞非Number類型的參數會被認定為file_id,那么返回的是文件上傳隊列(通過文件檢測,准備好進行上傳的文件)數組中id為file_id的文件對象。如果參數為空,或者沒有此id的文件對象,那么返回文件等待隊列中的第一個文件對象,如果第一個文件對象為空,那么返回null。
void addPostParam(name, value)
給設置中的post_params對象添加值對,當文件上傳的時候,這個值對會一同在POST中發送。
如果設置的時候,post_params中以及存在該值,那么實際上會被覆蓋。
提醒:SWFUload存在Cookie bug,你可以使用此方法避免。
void removePostParam(name)
從設置中的post_params對象中刪除name指定的屬性,當文件上傳的時候,刪除的值對不會繼續在POST中發送。
bool addFileParam(file_id, name, value)
為指定file_id的特定文件對象添加POST值對,如果添加的name屬性已經存在,那么原值會被覆蓋。
如果需要給所有文件對象添加POST值,那么可以使用設置中的post_params屬性。
bool removeFileParam(file_id, name)
刪除由addFileParam添加的POST值對.
如果POST設置中沒有此屬性,那么返回false。
void setUploadURL(url)
動態修改設置中的upload_url屬性。
void setPostParams(param_object)
動態修改post_params,以前的屬性全部被覆蓋。param_object必須是一個JavaScript的基本對象,所有屬性和值都必須是字符串類型。
void setFileTypes(types, description)
動態修改設置中的file_types 和 file_types_description,兩個參數都是必須的。
void setFileSizeLimit(file_size_limit)
動態修改設置中的file_size_limit,此修改針對之后的文件大小過濾有效。file_size_limit參數接收一個單位,有效的單位有B、KB、MB、GB,默認單位是KB。
例如: 2147483648 B, 2097152, 2097152KB, 2048 MB, 2 GB
void setFileUploadLimit(file_upload_limit)
動態修改設置中的file_upload_limit,特殊值0表示無限制。
提醒:這里限制的是一個SWFUpload實例控制上傳成功的文件總數。
void setFileQueueLimit(file_queue_limit)
動態修改設置中的file_queue_limit,特殊值0表示無限制。
提醒:這里限制的是文件上傳隊列中(入隊檢測通過的文件會添加到上傳隊列等待上傳)允許排隊的文件總數。
void setFilePostName(file_post_name)
動態修改設置中的file_post_name,注意在Linux環境下,FlashPlayer是忽略此設置的。
void setUseQueryString(use_query_string)
動態修改設置中的use_query_string,設置為true的時候,SWFUpload以GET形式發送數據,如果為false,那么就以POST發送數據。
void setDebugEnabled(debug_enabled)
啟動/禁止 debug輸出,debug_enabled參數是一個布爾值。
void setButtonImageURL(url)
動態修改按鈕的圖片。url參數是相對於該swf文件或者是絕對地址的圖片(或者是SWF)。所有FLASH支持的圖片類型都可以使用(gif,jpg,png,或者是一個SWF)。
該按鈕圖片需要經過一定規則(CSS Sprite)的處理。按鈕圖片中需要包括按鈕的4個狀態,從上到下依次是normal, hover, down/click, disabled.(可以參照官方demo中的圖片)
void setButtonDimensions(width, height)
動態修改SWF影片的尺寸以適應Button的圖片大小。
void setButtonText(text)
動態設置Flash Button中顯示的文字,支持HTML。HTML文本的樣式可以通過CSS選擇器並配合setButtonTextStyle方法來設置。關於Flash文本對HTML的支持詳細可見 Adobe's Flash documentation。
void setButtonTextStyle(css_style_text)
配合setButtonText方法,可以通過CSS樣式來動態設置Flash Button中的文字樣式。關於Flash文本對CSS的支持詳細可見Adobe's Flash documentation
void setButtonTextPadding(left, top)
Sets the top and left padding of the Flash button text. The values may be negative.
void setButtonDisabled(isDisabled)
When 'true' changes the Flash Button state to disabled and ignores any clicks.
void setButtonAction(buttonAction)
Sets the action taken when the Flash button is clicked. Valid action values are taken from the BUTTON_ACTION constants.
void setButtonCursor(buttonCursor)
Sets the mouse cursor shown when hovering over the Flash button. Valid cursor values are taken from the BUTTON_CURSOR constants.
事件
SWFUpload在操作過程中會觸發一系列事件,開發者可以利用這些回調的處理事件來控制UI,控制操作或者報告錯誤。
所有的事件都是在SWFUpload實例的上下文中調用的,因此在這些回調的事件中使用this能夠直接訪問到該觸發該事件的實例對象。
所有事件應該在實例初始化時setting參數中預設完成。
flashReady()
該事件函數是內部事件,因此不能被重寫。當SWFupload實例化,加載的FLASH完成所有初始化操作時觸發此事件。
提醒:對應設置中的自定義事件swfupload_loaded_handler
swfUploadLoaded()
V2.1.0版本中已經刪除了此事件
fileDialogStart()
此事件在selectFile或者selectFiles調用后,文件選擇對話框顯示之前觸發。只能同時存在一個文件對話框。
提醒:對應設置中的自定義事件file_dialog_start_handler
fileQueued(file object)
當文件選擇對話框關閉消失時,如果選擇的文件成功加入上傳隊列,那么針對每個成功加入的文件都會觸發一次該事件(N個文件成功加入隊列,就觸發N次此事件)。
提醒:對應設置中的自定義事件file_queued_handler
fileQueueError(file object, error code, message)
當選擇文件對話框關閉消失時,如果選擇的文件加入到上傳隊列中失敗,那么針對每個出錯的文件都會觸發一次該事件(此事件和fileQueued事件是二選一觸發,文件添加到隊列只有兩種可能,成功和失敗)。
文件添加隊列出錯的原因可能有:超過了上傳大小限制,文件為零字節,超過文件隊列數量限制,設置之外的無效文件類型。
具體的出錯原因可由error code參數來獲取,error code的類型可以查看SWFUpload.QUEUE_ERROR中的定義。
提醒:對應設置中的自定義事件file_queue_error_handler
注意:如果選擇入隊的文件數量超出了設置中的數量限制,那么所有文件都不入隊,此事件只觸發一次。如果沒有超出數目限制,那么會對每個文件進行文件類型和大小的檢測,對於不通過的文件觸發此事件,通過的文件成功入隊。
fileDialogComplete(number of files selected, number of files queued)
當選擇文件對話框關閉,並且所有選擇文件已經處理完成(加入上傳隊列成功或者失敗)時,此事件被觸發,number of files selected是選擇的文件數目,number of files queued是此次選擇的文件中成功加入隊列的文件數目。
提醒:對應設置中的自定義事件file_dialog_complete_handler
注意:如果你希望文件在選擇以后自動上傳,那么在這個事件中調用this.startUpload() 是一個不錯的選擇。如果需要更嚴格的判斷,在調用上傳之前,可以對入隊文件的個數做一個判斷,如果大於0,那么可以開始上傳。
uploadStart(file object)
在文件往服務端上傳之前觸發此事件,可以在這里完成上傳前的最后驗證以及其他你需要的操作,例如添加、修改、刪除post數據等。
在完成最后的操作以后,如果函數返回false,那么這個上傳不會被啟動,並且觸發uploadError事件(code為ERROR_CODE_FILE_VALIDATION_FAILED),如果返回true或者無返回,那么將正式啟動上傳。
提醒:對應設置中的自定義事件upload_start_handler
uploadProgress(file object, bytes complete, total bytes)
該事件由flash定時觸發,提供三個參數分別訪問上傳文件對象、已上傳的字節數,總共的字節數。因此可以在這個事件中來定時更新頁面中的UI元素,以達到及時顯示上傳進度的效果。
注意: 在Linux下,Flash Player只在所有文件上傳完畢以后才觸發一次該事件,官方指出這是Linux Flash Player的一個bug,目前SWFpload庫無法解決(我沒有測試過)。
提醒:對應設置中的自定義事件upload_progress_handler
uploadError(file object, error code, message)
無論什么時候,只要上傳被終止或者沒有成功完成,那么該事件都將被觸發。error code參數表示了當前錯誤的類型,更具體的錯誤類型可以參見SWFUpload.UPLOAD_ERROR中的定義。Message參數表示的是錯誤的描述。File參數表示的是上傳失敗的文件對象。
例如,我們請求一個服務端的一個不存在的文件處理頁面,那么error code會是-200,message會是404。停止、退出、uploadStart返回false、HTTP錯誤、IO錯誤、文件上傳數目超過限制等,都將觸發該事件,Upload error will not fire for files that are cancelled but still waiting in the queue。(對於官方的這句話我還存在疑問,文件退出以后怎么還會保留在文件上傳隊列中保留呢?)
提醒:對應設置中的自定義事件upload_error_handler
注意:此時文件上傳的周期還沒有結束,不能在這里開始下一個文件的上傳。
uploadSuccess(file object, server data)
當文件上傳的處理已經完成(這里的完成只是指向目標處理程序發送了Files信息,只管發,不管是否成功接收),並且服務端返回了200的HTTP狀態時,觸發此事件。
提醒:對應設置中的自定義事件upload_success_handler
- server data是服務端處理程序返回的數據。
- 此時文件上傳的周期還沒有結束,不能在這里開始下一個文件的上傳。
- 在window平台下,那么服務端的處理程序在處理完文件存儲以后,必須返回一個非空值,否則此事件不會被觸發,隨后的uploadComplete事件也無法執行。
uploadComplete(file object)
當上傳隊列中的一個文件完成了一個上傳周期,無論是成功(uoloadSuccess觸發)還是失敗(uploadError觸發),此事件都會被觸發,這也標志着一個文件的上傳完成,可以進行下一個文件的上傳了。
如果要進行多文件自動上傳,那么在這個時候調用this.startUpload()來啟動下一個文件的上傳是不錯的選擇。
提醒:對應設置中的自定義事件upload_complete_handler
注意:當在進行多文件上傳的時候,中途用cancelUpload取消了正在上傳的文件,或者用stopUpload停止了正在上傳的文件,那么在uploadComplete中就要很小心的使用this. startUpload(),因為在上述情況下,uploadError和uploadComplete會順序執行,因此雖然停止了當前文件的上傳,但會立即進行下一個文件的上傳,你可能會覺得這很奇怪,但事實上程序並沒有錯。如果你希望終止整個隊列的自動上傳,那么你需要做額外的程序處理了。
debug(message)
如果debug setting設置為true,那么頁面底部會自動添加一個textArea, SWFUpload庫和Flash都會調用此事件來在頁面底部的輸出框中添加debug信息供調試使用。
提醒:對應設置中的自定義事件debug_handler
SWFUpload功能對象
Settings object
它是一個Object類型的變量,為SWFUpload的實例初始化提供配置。 其中的每一個配置屬性都只能出現一次。 很多屬性都是可選的,如果可選屬性沒有被配置,那么會使用SWFUpload庫中默認指定的合適的值,具體可查看setting的詳細介紹。
例如:(setting可以配置的所有屬性)
{ upload_url : "http://www.swfupload.org/upload.php", flash_url : "http://www.swfupload.org/swfupload.swf", file_post_name : "Filedata", post_params : { "post_param_name_1" : "post_param_value_1", "post_param_name_2" : "post_param_value_2", "post_param_name_n" : "post_param_value_n" }, use_query_string : false, requeue_on_error : false, http_success : [201, 202], file_types : "*.jpg;*.gif", file_types_description: "Web Image Files", file_size_limit : "1024", file_upload_limit : 10, file_queue_limit : 2, debug : false, prevent_swf_caching : false, button_placeholder_id : "element_id", button_image_url : "http://www.swfupload.org/button_sprite.png", button_width : 61, button_height : 22, button_text : "<b>Click</b> <span class="redText">here</span>", button_text_style : ".redText { color: #FF0000; }", button_text_left_padding : 3, button_text_top_padding : 2, button_action : SWFUpload.BUTTON_ACTION.SELECT_FILES, button_disable : false, button_cursor : SWFUpload.BUTTON_CURSOR.HAND, button_window_mode : SWFUpload.WINDOW_MODE.TRANSPARENT, swfupload_loaded_handler : swfupload_loaded_function, file_dialog_start_handler : file_dialog_start_function, file_queued_handler : file_queued_function, file_queue_error_handler : file_queue_error_function, file_dialog_complete_handler : file_dialog_complete_function, upload_start_handler : upload_start_function, upload_progress_handler : upload_progress_function, upload_error_handler : upload_error_function, upload_success_handler : upload_success_function, upload_complete_handler : upload_complete_function, debug_handler : debug_function, custom_settings : { custom_setting_1 : "custom_setting_value_1", custom_setting_2 : "custom_setting_value_2", custom_setting_n : "custom_setting_value_n", } }
Settings 描述
upload_url
默認值:空字符串
upload_url設置接收的是一個絕對的或者相對於SWF文件的完整URL。推薦使用完整的絕對路徑,以避免由瀏覽器和FlashPlayer修改了基准路徑設置而造成的請求路徑錯誤。
注意:這里需要考慮FlashPlayer的安全域模型。
file_post_name
默認值:Filedata
該參數設置了POST信息中上傳文件的name值(類似傳統Form中設置了<input type="file" name="uploadImg"/>的name屬性)。
注意:在Linux下面此參數設置無效,接收的name總為Filedata,因此為了保證最大的兼容性,建議此參數使用默認值。
post_params
默認值:空的Object對象
post_params定義的是一個包含值對的object類型數據,每個文件上傳的時候,其中的值對都會被一同發送到服務端。
use_query_string
默認值:false
該屬性可選值為true和false,設置post_params是否以GET方式發送。如果為false,那么則以POST形式發送。
requeue_on_error
默認值:false
該屬性可選值為true和false。如果設置為true,當文件對象發生uploadError時(除開fileQueue錯誤和FILE_CANCELLED錯誤),該文件對象會被重新插入到文件上傳隊列的前端,而不是被丟棄。如果需要,重新入隊的文件可以被再次上傳。如果要從上傳隊列中刪除該文件對象,那么必須使用cancelUpload方法。
跟上傳失敗關聯的所有事件同樣會被一一觸發,因此將上傳失敗的文件重新入隊可能會和Queue Plugin造成沖突(或者是自動上傳整個文件隊列的自定義代碼)。如果代碼中調用了startUpload方法自動進行下一個文件的上傳,同時也沒有采取任何措施讓上傳失敗的文件退出上傳隊列,那么這個重新入隊的上傳失敗的文件又會開始上傳,然后又會失敗,重新入隊,重新上傳...,進入了無止境的循環。
該設置是在v2.1.0中引入的。
http_success
默認值:[]
該數組可自定義觸發success事件的HTTP狀態值。200的狀態值始終會觸發success,並且只有200的狀態會提供serverData。
當接受一個200以外的HTTP狀態值時,服務端不需要返回內容。
file_types
默認值:*.*
設置文件選擇對話框的文件類型過濾規則,該屬性接收的是以分號分隔的文件類型擴展名,例如“ *.jpg;*.gif”,則只允許用戶在文件選擇對話框中可見並可選jpg和gif類型的文件。默認接收所有類型的文件。
提醒:該設置只是針對客戶端瀏覽器的過濾,對服務端的文件處理中的文件類型過濾沒有任何限制,如果你需要做嚴格的文件過濾,那么服務端同樣需要程序檢測。
file_types_description
默認值:All Files
設置文件選擇對話框中顯示給用戶的文件描述。
file_size_limit
默認值:0
設置文件選擇對話框的文件大小過濾規則,該屬性可接收一個帶單位的數值,可用的單位有B,KB,MB,GB。如果忽略了單位,那么默認使用KB。特殊值0表示文件大小無限制。
提醒:該設置只對客戶端的瀏覽器有效,對服務端的文件處理沒有任何限制,如果你需要做嚴格文件過濾,那么服務端同樣需要程序處理。
file_upload_limit
默認值:0
設置SWFUpload實例允許上傳的最多文件數量,同時也是設置對象中file_queue_limit屬性的上限。一旦用戶已經上傳成功或者添加文件到隊列達到上最大數量,那么就不能繼續添加文件了。特殊值0表示允許上傳的數量無限制。只有上傳成功(上傳觸發了uploadSuccess事件)的文件才會在上傳數量限制中記數。使用setStats方法可以修改成功上傳的文件數量。
注意:該值不能跨頁面使用,當頁面刷新以后該值也被重置。嚴格的文件上傳數量限制應該由服務端來檢測、管理。
file_queue_limit
默認值:0
設置文件上傳隊列中等待文件的最大數量限制。當一個文件被成功上傳,出錯,或者被退出上傳時,如果文件隊列中文件數量還沒有達到上限,那么可以繼續添加新的文件入隊,以頂替該文件在文件上傳隊列中的位置。如果允許上傳的文件上限(file_upload_limit)或者剩余的允許文件上傳數量小於文件隊列上限(file_queue_limit),那么該值將采用這個更小的值。
flash_url
默認值:空字符串
設置絕對或者相對於此上傳頁面的完整URL,一旦SWFupload實例化以后,此設置不能再被修改。
提醒:測試發現使用setUploadURL方法是可以修改此設置的。
flash_width
固定值:1px
(v2.1.0已刪除) 設置插入flash影片的HTML元素容器的寬度。如果此設置小於1像素,一些瀏覽器會出現功能異常。 因此該值在v2.1.0中刪除了自定義設置,默認設置為1像素了。
flash_height
固定值:1px
(v2.1.0已刪除) 設置插入flash影片的HTML元素容器的高度。如果此設置小於1像素,一些瀏覽器會出現功能異常。 因此該值在v2.1.0中刪除了自定義設置,默認設置為1像素了。
flash_color
默認值:#FFFFFF
(v2.2.0已刪除) 設置HTML頁面中的flash背景色,默認為#FFFFFF
prevent_swf_caching
默認值:true
(v2.2.0新增)該布爾值設置是否在Flash URL后添加一個隨機值,用來防止瀏覽器緩存了該SWF影片。這是為了解決一些基於IE-engine的瀏覽器上的出現一個BUG。
提醒:SWFUpload是直接在flash_url后添加了一個swfuploadrnd的隨機參數。如果你給定的flash_url中已經存在了GET類型的參數,那么就會出現兩個問號連接符導致錯誤。
debug
默認值:false
該值是布爾類型,設置debug事件是否被觸發。
注意:SWFUpload代碼中是將此變量和字符串true做的恆等判斷,因此它只認定true為DEBUG模式開啟,如果設置為1,雖然JS認定是開啟模式,並且在初始化完畢后會有生成Debug Console,但后續操作中FLASH不會輸出調試信息。(因為我習慣用1和0代表布爾變量,因此一度疑惑為何Flash的debug信息無法輸出。)
button_placeholder_id
默認值:null
(v2.2.0新增) 該必要參數指定了swfupload.swf將要替換的頁面內的DOM元素的ID值。當對應的DOM元素被替換為SWF元素時,SWF的容器會被添加一個名稱為"swfupload"的樣式選擇器供CSS自定義使用。
button_image_url
默認值:空字符串
(v2.2.0新增) V2.2.0版最大的改變就是引入了一個按鈕到SWF中,利用該參數可以設置一個相對於該swf文件或者是絕對地址的圖片(或者是SWF),作為按鈕的UI展現。所有FLASH支持的圖片類型都可以使用(gif,jpg,png,或者是一個SWF)。
該按鈕圖片需要經過一定規則(CSS Sprite)的處理。按鈕圖片中需要包括按鈕的4個狀態,從上到下依次是normal, hover, down/click, disabled.(可以參照官方demo中的圖片)
button_width
默認值:1
(v2.2.0新增) 設置該SWF的寬度屬性。
button_height
默認值:1
(v2.2.0新增)設置該SWF的高度屬性(按鈕圖片高度的1/4)
button_text
默認值:空字符串
(v2.2.0新增) 該屬性設置Flash Button中顯示的文字,支持HTML。HTML文本的樣式可以通過CSS選擇器並配合button_text_style參數來設置。關於Flash文本對HTML的支持詳細可見 Adobe's Flash documentation。
button_text_style
默認值:"color: #000000; font-size: 16pt;"
(v2.2.0新增)此參數配合button_text參數,可以通過CSS樣式來設置Flash Button中的文字樣式。關於Flash文本對CSS的支持詳細可見Adobe's Flash documentation
button_text_top_padding
默認值:0
(v2.2.0新增) 設置Flash Button上文字距離頂部的距離,可以使用負值。
button_text_left_padding
默認值:0
(v2.2.0新增) 設置Flash Button上文字距離左側的距離,可以使用負值。
button_action
默認值:SWFUpload.BUTTON_ACTION.SELECT_FILES(多文件上傳)
(v2.2.0新增) 設置Flash Button點擊以后的動作。默認為SWFUpload.BUTTON_ACTION.SELECT_FILES,點擊按鈕將會打開多文件上傳的對話框。如果設置為SWFUpload.BUTTON_ACTION.SELECT_FILE,則為單文件上傳。如果設置為SWFUpload.BUTTON_ACTION.START_UPLOAD,則啟動文件上傳。
button_disabled
默認值:false
(v2.2.0新增) 該布爾值設置Flash Button是否是禁用狀態。當它處於禁用狀態的時候,點擊不會執行任何操作。
button_cursor
默認值:SWFUpload.CURSOR.ARROW(箭頭光標)
(v2.2.0新增) 此參數可以設置鼠標划過Flash Button時的光標狀態。默認為SWFUpload.CURSOR.ARROW,如果設置為SWFUpload.CURSOR.HAND,則為手形
button_window_mode
默認值:SWFUpload.WINDOW_MODE.WINDOW
(v2.2.0新增) 此參數可以設置瀏覽器具體以哪種模式顯示該SWF影片。
custom_settings
默認值:空的Object對象
該屬性接收一個Object類型數據,可用於安全地存儲與SWFUpload實例關聯的自定義信息,例如屬性和方法,而不用擔心跟SWFUpload內部的方法和屬性沖突以及版本升級的兼容。
設置完畢以后,可以通過實例的customSettings屬性來訪問。
var swfu = new SWFUpload({ custom_settings : { "My Setting" : "This is my setting", myothersetting : "This is my other setting", integer_setting : 100, a_dom_setting : document.getElementById("some_element_id") } }); var my_setting = swfu.customSettings["My Setting"]); swfu.customSettings["My Setting"] = "This is my new setting"; swfu.customSetting.myothersetting = "another new value"; swfu.customSetting.integer_setting += 25; swfu.customSetting["a_dom_setting"].style.visibility = "hidden";
Event Handlers
默認值:null
剩下的設置定義的是一系列事件處理的回調函數,在SWFUpload的操作過程中相應的事件會被觸發。如果你需要在這些回調中進行自定義操作,那么你應該在設置中定義對應的JavaScript函數。
File Object
File Object包含了一組可用的文件屬性,很多處理事件都會傳遞一個File Object參數來訪問該文件的相關屬性。
{ id : string, // SWFUpload控制的文件的id,通過指定該id可啟動此文件的上傳、退出上傳等 index : number, // 文件在選定文件隊列(包括出錯、退出、排隊的文件)中的索引,getFile可使用此索引 name : string, // 文件名,不包括文件的路徑。 size : number, // 文件字節數 type : string, // 客戶端操作系統設置的文件類型 creationdate : Date, // 文件的創建時間 modificationdate : Date, // 文件的最后修改時間 filestatus : number // 文件的當前狀態,對應的狀態代碼可查看SWFUpload.FILE_STATUS }
Stats Object
該對象提供了上傳隊列的狀態信息,訪問實例的getStats方法可獲取此對象。
該對象包括下面屬性:
{ in_progress : number // 值為1或0,1表示當前有文件正在上傳,0表示當前沒有文件正在上傳 files_queued : number // 當前上傳隊列中存在的文件數量 successful_uploads : number // 已經上傳成功(uploadSuccess觸發)的文件數量 upload_errors : number // 已經上傳失敗的文件數量 (不包括退出上傳的文件) upload_cancelled : number // 退出上傳的文件數量 queue_errors : number // 入隊失敗(fileQueueError觸發)的文件數量 }
所有這些屬性的值都可以使用setStats方法來修改,除了in_progress 和 files_queued。
SWFUpload 插件
With SWFUpload v2.0 several plugins have been introduced. They are provided to help with common tasks associated with implementing SWFUpload.
Currently most of the documentation for using the plugins is contained in the plugin JavaScript file.
SWFObject
The SWFObject plugin uses the SWFObject library to handle the embedding of the SWFUpload Flash Component into the page.
This plugin also provides support for Document Ready loading and Flash Version Detection. Usage details are documented in the plugin file itself.
Using this plugin can eliminate the flicker seen in the Graceful Degradation plugin and provides events for loading failure.
Flash Player 10: Because Flash Player 10 requires the SWFUpload swf to act is a button the movie must be visible in order for it to load. If the button_placeholder_id is set to an element that is hidden (visibility set to hidden or display set to none) SWFUpload will fail to load.
Graceful Degradation
This plugin has been superseded by the SWFObject plugin.
This plugin provides additional settings and logic for automatically hiding and showing page elements based on whether SWFUpload loads.
Flash Player 10: The Graceful Degradation plugin has been updated to support Flash Player 10. However, because the Flash Movie won't execute if it is hidden (inside an element with visibility set to hidden or display set to none) the movie must be loaded in a visible area of the page. This is handled automatically. However, the side affect is that the movie is executed twice. The plugin handles this but developers should be aware that this is happening. In most cases this simply means that you will see the SWFUpload initialization (if debug is enable) run twice. There is still only a single movie per instance and events are not fired twice.
SWFUpload v1.0.2 Compatibility
Creates compatibility with v1.0.2. Using this plugin you should be able to drop SWFUpload v2.0 in to a v1.0.2 page. This plugin is not supported and is only intended for users of SWFUpload v1.0.2 who wish to upgrade to v2 without recoding their pages.
Cookies
In response to the Flash Cookie Bug the Cookies Plugin automatically retrieves your browser's cookies and sends them with the upload. The are sent as POST or GET variables to the upload url.
Queue Handling
This plugin provides Queue Handling features such as entire queue uploading, entire queue cancelling and automatic starting of uploads after being queued.
Known Issues
The Flash Player and many Browsers have bugs that have a direct impact on the performance of SWFUpload. While we have worked hard to get around many issues there are some things that cannot be fix.
Cancelling in Linux
Older Flash 9 Players for Linux cause the browser to crash if an upload is cancelled. Newer Flash 9 Players behave better.
Upload Progress in Linux
The Flash Player in Linux sends a single uploadProgress event after the file has finished uploading.
Upload Progress in OS X
There have been some reports that uploadProgress events are not fired in MAC Flash Players. The specifics haven't been pinned down but be aware of the possible issue.
MIME Type
The Flash Player uploads all files with a mime type of application/octet-stream regardless of the file's actual mime type.
Maximum number of selected files
The Flash Player does not impose a maximum number of selected files. However, it builds a selected files string which does have a maximum length. The string is built using the file's name and the separator [quote][space][quote]. The total number of files selected is determined by the sum of the lengths of the file names and a prefixed and postfixed [quote] character (2 characters) and the number of files selected minus one times 3 (for the separator string)
This limitation may vary from system to system. If a use selects too many files they will be receive a Flash Player generated warning message and will be left at the File Selection Dialog.
Proxies
The Flash Player may not properly use proxies. It does not handle authenticating proxies well (if at all) and will some-times crash.
Some anti-virus software uses a proxy to scan uploads and cause SWFUpload to believe the entire file has been uploaded. SWFUpload will fire uploadProgress events very quickly until it reaches 100% and will then seem to pause until the proxy completes uploading the file to the server.
Apache mod_security
Apache's mod_security validates POST to the server. Flash Player has implemented an edge case (there is argument as to whether it is invalid or note) POST for file uploads and so servers implementing mod_security will reject the upload. mod_security can be disabled using your .htaccess file
SSL
There have been some reports that the Flash Player cannot upload through SSL. The issue has not been pinned down but uploading over SSL may be unreliable. There especially seems to be an issue with using self-signed certificates.
Also, SSL tickets from untrusted Certificate Authorities (CA) do not work as Flash does not provide a method for accepting the certificate. It has been noted that, like the cookie bug, that Flash Player on Windows obtains its trusted CA list from Internet Explorer regardless of the browser in use.
Authentication
HTTP Authentication is not well supported by the Flash Player. Later versions of Flash Player behave better. Old version of Flash Player would crash the browser.
Prematurely terminated connections
Prematurely ending the response (such as a Response.end() in ASP.Net) can sometimes cause successful uploads to be reported as failed.
Filedata in Linux
Changing the Filedata value (file_post_name setting) is ignored in Linux Flash Player.
uploadSuccess & Server Data
The uploadSuccess will not fire if no data is returned from the server. This is especially problematic on the Mac version of the Flash Player.
Cookie issue
On Windows the Non-IE Flash Player plugin (FireFox, Opera, Safari, etc) sends the IE cookies regardless of the browser used. This breaks authentication and sessions for many server-side scripting technologies.
Developers should manually pass Session and Authentication cookie information and manually restore Sessions on the Server Side if they wish to use Sessions
The SWFUpload package contains work-around sample code for PHP and ASP.Net
ExternalInterface bugs
Flash Player does not properly escape data when communication with the browser/JavaScript. SWFUpload goes to great lengths to work-around this issue. If this bug is fixed in future Flash Players/Browsers then SWFUpload will send extra escaped data.
Server Data length bugs
Very long server data is corrupted on Mac and Linux Flash Players. Server data will be truncated, garbled, and/or repeated. We recommend keeping data returned from the server short and concise.
Avant Browser
For some users the Avant Browser does not work with SWFUpload after the Flash Control has been cached. This has been reproduced by the SWFUpload developers but the Avant Browser developers did not experience any problems.
When the page is reloaded SWFUpload loads and fires the swfupload_loaded event. However, none of the ExternalInterface callback functions are defined on the movie element. SWFUpload v2.0.2 has added checks which prevent swfupload_loaded from firing if the callback functions are not detected.
SWFUpload v2.2.0 added the prevent_swf_caching setting that attempts to work around this issue.
File Dialog & Page Changing
Leaving or reloading the current page while the File Browser Dialog window is open will cause the browser to crash (all browsers, all OSs). Most commonly this is caused by failing to cancel a click event on an <a> tag where the onclick event calls the selectFile or selectFiles function.
Long Running Upload Scripts
After Flash has uploaded the file to the webserver the upload script is executed. This script handles the file whether that means saving it, creating a thumbnail, scanning for viruses, etc. If the upload script does not return any data within 30 seconds Flash will disconnect and return an IO Error. You can prevent this by returning characters or data while the script runs (if possible). For PHP, the script continues to run and complete successfully even though Flash has terminated the connection. Any data returned by the script after Flash has disconnected is lost.
Other Mac Issues
- Users have reported that uploading to subdomains does not work with the Mac Flash Player.
- Users have reported that pages that redirect (HTTP Status 302) are not handled by the Mac Flash Player. Windows clients seem to handle this issue.
- The flash documentation states that on OS early than OS X 10.3 the bytes loaded is always reported as -1. SWFUpload converts this to 0 but the total bytes will never be sent and 100% won't be reached. The UI should be updated to display 100% complete in uploadSuccess or uploadComplete events to maintain a consistent UI.
- Some users have reported issues if there is a space character in the upload_url for the Mac Flash Player. Avoid spaces or try replacing them with + or %20.
- Users have reported that the Flash Player for Mac adds the PORT to the HTTP_HOST server variable (e.g., http://www.example.com:80). If you are checking this variable in your server-side script be aware of the possible issue.
