- Initialization and Settings (JavaScript)
- JavaScript library: SWFUpload.js
- Flash Control: swfupload.swf
- The Event Handlers (JavaScript)
Initialization and Settings
var swfu;
window.onload = function () {
var settings_object = {
upload_url : "http://www.swfupload.org/upload.php",
flash_url : "http://www.swfupload.org/swfupload.swf",
file_size_limit : "20 MB",
button_placeholder_id : "spanSWFUploadButton"
};
swfu = new SWFUpload(settings_object);
};
JavaScript library
Example: Adding SWFUpload.js to a page
The Event Handlers
Example: SWFUpload event handlers and initialization.
// The uploadStart event handler. This function variable is assigned to upload_start_handler in the settings object
var myCustomUploadStartEventHandler = 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;
};
// The uploadSuccess event handler. This function variable is assigned to upload_success_handler in the settings object
var myCustomUploadSuccessEventHandler = function (file, server_data, receivedResponse) {
alert("The file " + file.name + " has been delivered to the server. The server responded with " + server_data); }; // Create the SWFUpload Object
var swfu = new SWFUpload({
upload_url : "http://www.swfupload.org/upload.php",
flash_url : "http://www.swfupload.org/swfupload.swf",
file_size_limit : "200 MB",
upload_start_handler : myCustomUploadStartEventHandler,
upload_success_handler : myCustomUploadSuccessEventHandler }
);
DEMO:
http://demo.swfupload.org/v220/index.htm
沒有留言:
張貼留言