Uploading files using XMLHTTP blocks

Source: Internet
Author: User
Tags array base64 object end return zip client access
xml| Upload

Writing ideas: The local file in the client through the base64 encoding after sending the destination.
During the test, the upload file was too large, which caused the timeout to be unsuccessful.
It was later improved. Send the code segment. Test 20M Success

Writing purpose: In the traditional solution, one at a time to select upload can. But it's a hassle when it comes to reading the file path in the database and uploading the files to a place.
If you get the path one to find with FTP of course is also OK, but every time I look for these files will be more time-consuming. This is done primarily to get files through the file path in the database. Upload files to one place at a time.
The main purpose is to exercise yourself.

Workaround: Initially try to use the analog keyboard input to forcibly assign the value to the file control to upload it in a traditional way. However, the old encountered a null value of the situation, so many documents have not been sent out. Look up some information, now is to take all the path through the database and then write to a JS. Then in the foreground with JS read these paths, through the XMLHTTP to send files.
Because IE does not like XMLHTTP. Always think he has malicious behavior. So always talk about warning. Therefore, you cannot use the Web path when you operate. You can only access it using a physical path.
The server then has a file to receive the encoding and decode it. So I call it "C/S." '

At present, a lot of code is still in perfect.
Brief introduction:

Aryfiles.push ("C:\\aaa.zip");
Aryfiles.push ("C:\\bbb.exe");
This is the file path and file. Available for multiple
This path can also be used by the file control on the client to access the

http://www.xrss.cn/xxx/xxx.asp
This is the destination, you can change to the address you want.

Ado_stream. LoadFromFile (Server.MapPath (".") & "/" & + Str_filename)
Server.MapPath (".") & "/" & + Str_filename Here is the read file.
Server.MapPath (".") & "/" & Path and storage path consistent

Ado_stream. SaveToFile Server.MapPath (".") & "/" & str_filename,2
Server.MapPath (".") & "/" & This is the path for storing files. Str_filename as FileName

Here the reading and storing are placed in the directory where the program is placed. You can keep it that way when you test it.

Place the first piece of code locally (eg:c:\upload.htm)

Put the second piece of code on the server, can be a local server, can be a public network server. Consistent with the destination above
(eg:http://www.xrss.cn/upload.asp or http://localhost/www/upload.asp)


Action: Locate the first paragraph where the code is saved. Execute (eg: Open C-Disk to perform upload.htm)

Customer segment


1
2
3
4 5value= "Send"/>

7width=300px>


8id=div_message>
9
10
18
70
Server-side
1<%@ language=vbscript%>
2<% Option Explicit
3response.expires = 0
4
5 ' Define variables and objects.
6dim Ado_stream
7dim Xml_dom
8dim Xml_data
9dim Str_filename
10dim Bol_partstart
11dim Int_partid
12dim Bol_partend
13
14 ' Create Stream Object
15set Ado_stream = Server.CreateObject ("ADODB"). Stream ")
16 ' Create Xmldom object from Request object
17set xml_dom = Server.CreateObject ("MSXML2"). DOMDocument ")
18xml_dom.load (Request)
19 ' Read the node that contains the binary data
20set xml_data = Xml_dom.selectsinglenode ("Root/updata")
21str_filename = Xml_data.getattribute ("filename")
22bol_partstart = CBool (Xml_data.getattribute ("Partstart"))
23int_partid = CInt (Xml_data.getattribute ("PartID"))
24bol_partend = CBool (Xml_data.getattribute ("Partend"))
25
26 ' open stream object, deposit data into it
27ado_stream. Type = 1 ' 1=adtypebinary
28ado_stream.open
29if not Bol_partstart Then
Ado_stream. LoadFromFile (Server.MapPath (".") & "/" & + str_filename) ' Read file
Ado_stream.position = Ado_stream.size
32end if
33ado_stream. Write Xml_data.nodetypedvalue
34 ' File for filing
35ado_stream. SaveToFile Server.MapPath (".") & "/" & str_filename,2
36 ' Save File 2=adsavecreateoverwrite
37ado_stream.close
38
39 ' Releasing resources
40set Ado_stream = Nothing
41set Xml_dom = Nothing
42 ' Return information to browser
43response.write "Upload successful!" & Str_filename & Int_partid & Bol_partstart
44%>



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.