SWFUpload ASP Upload Sample code

Source: Internet
Author: User
Tags documentation file size file upload new features php and relative

The main problem that swfupload (hereinafter referred to as SU) is that there is a great difference between versions, and now the version has reached 2.1beta. I use the 2.02 version, the use of the 1.xx version.

The differences are embodied in:
Lash_url: ". /swfupload/swfupload_f8.SWF"
Upload_url: ". /multiuploaddemo/Upload. php ",
function uploadsuccess (fileobj, Server_data)
If Flash_url is using F8.SWFSoUpload_url to use relativeSWFIf the F9 is used.SWFSoUpload_url to use the relative Current Program page (JSP,ASPThis is the path that has delayed me for a long time. If you want to use Server_data to pass the return value, you must also use F9.SWF, and it took me a lot of time. Anyway, Su provides all the source code, there are problems can be self-study, if you can look like me understand, hehe.

SU uses the upload function of Flash (Flash.net.FileReference;), and also uses the application programming interface for direct communication between ActionScript and the container of Flash Player externalinterface ( See appendix below),

Su super easy to use, and powerful, can upload multiple files at one time, can be in the client to verify the file type and size, but also in the upload progress control, can be sent back after the file feedback information, there is a better Debug dialog box, such as to see its advanced example:/HTTP Demo.swfupload.org/featuresdemo/index.php The only downside is the lack of support for Chinese filenames. I studied for a half day its flash as script, did not understand how to change the Chinese problem.

Its online documentation: http://demo.swfupload.org/Documentation/

The following is specific about how to use Su.
Suppose there is a front pageUpload.ASP, a background file to receive the page save.ASP, and Su's core file swfupload.js, auxiliary processing script handlers.js.
1, these two JS, the source code on the Internet, the core JS do not change. Handlers can be used directly, can also write their own, see the ability of everyone.
The core JS, mainly to see SWFUpload.prototype.initSettings initialization settings, a lot of parameters how to write, you can refer to it.
2, to call the two JS in the foreground page, and then initialize the Swfu object. Collapse Expand JavaScript Copy Code
<script type= "Text/javascript" >
var swfu;
Window.onload = function () {
SWFU = new SWFUpload ({
Backend Settings
Upload_url: "Upload.ASP",//Relative to theSWFFile is the place that misled me.
File_post_name: "Filedata",//the name of the file object, the default Filedata, can be changed by itself. Background receive it to identify
Post_params: {"sessid": "<%=session". Sessionid%> "},//additional parameters, version 2 new features

FileUploadSettings
File_size_limit: "204",//per KB, limit file size
File_Types: "*.jpg",//allowed file types
File_types_description: "JPG Images",//File type in dialog box
File_Upload_limit: "0",

Event Handler Settings-these functions as defined in Handlers.js
The handlers is not part of SWFUpload but is part of my website and control how
My website reacts to the SWFUpload events.
Event handling, you can expand your own inside the handlers.js, greatly facilitates the developer
is to define the following function in the handlers, of course, function inside can do nothing, or with the source code comes with the line
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 note is F8 or F9

Custom_settings: {
Upload_target: "Divfileprogresscontainer"
},

Debug Settings Whether debug information is turned on, default false
Debug:true
});
}
</script>

Here is how the form is written, without input type=file xml/html copy the Code
<form>
<button id= "Btnbrowse" type= "button" style= "padding:5px;" onclick= "swfu.selectfiles (); This.blur (); " >select Images <span style= "FONT-SIZE:7PT;" > (2 MB Max) </span></button>
</form>
3, background save.ASP.
In fact, if you have done ordinary file upload, here is very simple, whether it is JSP,ASP, PHP, the basic principles are the same. Front deskSWFAfter the file is obtained, it is still submitted to the background by post, and the file object is named Filedata by default. Like withASPThe process of uploading a component-free file is as followsASP/visual Basic Copy Code
<!--#include file= "Upload_5xsoft.inc "-
<%
SetUpload=newUpload_5xsoft
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 do you deal with it in Java? In fact, there are, for example, with struts, there is a Fileitem object named Filedata in Actionform.
PHP and aspx do not speak, the official source files are examples of PHP, as well as an example of ASPX.

4, how is the result displayed?
For example, the third step above returns a result "OK". Write JavaScript copy code in handlers
function uploadsuccess (fileobj, Server_data) {
try {
document.write (Server_data);
} catch (ex) {this.debug (ex);}
}

It's just so simple. You can write more complex effects as long as you know the principle. The official source code provides an example of creating thumbnails based on uploaded images and displaying them immediately.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.