The main problem encountered by swfupload (hereinafter referred to as Su) is the great difference caused by different versions,
The current version has reached the 2.1 beta. I use version 2.02.
The differences are embodied in:
Lash_url: ".../swfupload/swfupload_f8.
SWF
"
Upload
_ URL: "../multiuploaddemo/Upload
. Php ",
Function uploadsuccess (fileobj, server_data)
If flash_url uses f8.SWF
, ThenUpload
_ Use relative URLsSWF
If f9.SWF
, ThenUpload
_ URL
To use the current program page (JSP,ASP
). If you want to use server_data to pass the returned value, you must use f9.SWF
, This is also spent
I have spent a lot of time. In any case, Su provides all the source code. If you have any problems, you can study it on your own.
Su uses the flash upload function (flash.net. filereference;), and uses
The Application Programming Interface externalinterface for direct communication between Flash Player containers (see the appendix below ),
Su is super easy to use and has powerful functions. It can upload multiple files at a time, check the file type and size on the client, and control the upload progress, can receive background feedback after the file is uploaded
Information, there is a good debug dialog box, such as look at its advanced example: http://demo.swfupload.org/featuresdemo/index.php
At present, the only problem may be poor support for Chinese file names. I have studied its flash as script for a long time and have not figured out how to solve the problem.
Its Online Documentation: http://demo.swfupload.org/Documentation/
The following describes how to use Su.
Assume there is a front-end pageUpload
.ASP
, One after
Save.ASP
And the core file swfupload. js of Su to help process the script handlers. js.
1. These two JavaScript codes are available in the source code on the Internet. The core JS does not need to be changed. handlers can be used directly, or you can write it by yourself.
In core JS, we mainly look at swfupload. Prototype. initsettings initialization settings. For how to write many parameters, refer to it.
2. call these two JavaScript codes on the front-end page and initialize the swfu object. Hide and expand JavaScript copy code
<SCRIPT type = "text/JavaScript">
VaR swfu;
Window. onload = function (){
Swfu = new swfupload ({
// Backend settings
Upload
_ URL:
"Upload
.ASP
",
// Relative toSWF
This is where file misleads me.
File_post_name: "filedata", // The name of the file object. The default value is filedata. You can change it by yourself. It is used to identify the Object received in the background.
Post_params: {"sessid": "<% = session. sessionid %> "},//
Additional parameter, new feature of Version 2
// FileUpload
Settings
File_size_limit: "204", // unit: kb, limit File Size
File_types: "*. jpg", // allowed file types
File_types_description: "JPG images", // file type in the dialog box
File _Upload
_ Limit
: "0 ",
// Event handler settings-these functions as defined in
Handlers. js
// The handlers are not part of swfupload but are part of my
Website and control how
// My website reacts to the swfupload events.
// Event processing, which can be expanded in handlers. JS, greatly facilitating developers
// Define the following function in handlers. Of course, nothing can be done in the function, or use the built-in function in the source code.
File_queue_error_handler: filequeueerror,
File_dialog_complete_handler: filedialogcomplete,
Upload
_ Progress_handler
: Uploadprogress,
Upload
_ Error_handler
: Uploaderror,
Upload
_ Success_handler
: Uploadsuccess,
Upload
_ Complete_handler
: Uploadcomplete,
// Flash settings
Flash_url: "JS/swfupload_f9.SWF
", // Relative to this
File: F8 or F9
Custom_settings :{
Upload
_ Target
: "Divfileprogresscontainer"
},
// Whether to enable debug settings. The default value is false.
Debug: True
});
}
</SCRIPT>
Below is the form writing method, without the input type = file Writing Method XML/html copy code
<Form>
<Button id = "btnbrowse" type = "button" style = "padding: 5px ;"
Onclick = "swfu. selectfiles (); this. Blur ();"> Src = "image/page_white_add.png" style = "padding-Right: 3px;
Vertical-align: bottom; "> Select images <span style =" font-size:
7pt; "> (2 MB max) </span> </button>
</Form>
3. save in the background.ASP
.
In fact, if you have uploaded a common file, it is very simple here, whether it is JSP,ASP
, PHP, the basic principles are the same. Front-endSWF
After the file is obtained, it is still submitted to the background in post mode.
Name filedata. For exampleASP
The method for uploading component-less files is as follows:ASP
/Copy code in Visual Basic
<! -- # Include file ="Upload
_ 5xsoft. Inc "-->
<%
SetUpload
= New
Upload
_ 5 xsoft
For each formname inUpload
. Objfile
Set file =Upload
. File ("filedata ")
File. saveas server. mappath (file. filename)
Set file = nothing
Next
SetUpload
= Nothing
Response. Write "OK"
%>
How to handle it in Java?
Actually, it already exists. For example, with Struts, there is a fileitem object named filedata in actionform.
PHP and aspx will not be mentioned. The official source file is an example of PHP, and there is also an example of Aspx.
4. How do I display the returned results?
For example, a result "OK" is returned in step 3 above. Write the Javascript copy code in handlers.
Function uploadsuccess (fileobj, server_data ){
Try {
Document. Write (server_data );
} Catch (Ex) {This. debug (Ex );}
}
This is simple. As long as you know the principle, you can write more complex results. The official source code provides examples of generating thumbnails Based on uploaded images and displaying them immediately.