Instructions on the use of ADODB. Stream
Component: "ADODB. Stream"
There are the following methods:
Cancel Method
The usage is as follows:
Object. Cancel
Description: cancels the call of an asynchronous execute or open method suspended for execution.
Close Method
The usage is as follows:
Object. Close
: Close the object
Copyto Method
The usage is as follows:
Object. copyto (deststream, [charnumber])
Note: copy the data of the image. deststream points to the image to be copied. charnumber is an optional parameter, indicating the number of bytes to be copied. If not, it is all copied.
Flush Method
The usage is as follows:
Object. Flush
Note:
Loadfromfile Method
The usage is as follows:
Object. loadfromfile (filename)
Note: mount the file specified by filename into the object. The filename parameter is the specified user name.
Open Method
The usage is as follows:
Object. Open (source, [mode], [Options], [username], [Password])
Note: Open the object,
Parameter description: sourece object source, not specified
Mode specifies the open mode. Optional parameters are as follows:
Admoderead = 1
Admodereadwrite = 3
Admoderecursive = 4194304
Admodesharedenynone = 16
Admodesharedenyread = 4
Admodesharedenywrite = 8
Admodemo-exclusive = 12
Admodeunknown = 0
Admodewrite = 2
Options:
Adopenstreamasync = 1
Adopenstreamfromrecord = 4
Adopenstreamunspecified =-1
Username: Specifies the user name. Do not specify it.
Password specifies the password of the user name
Read Method
The usage is as follows:
Object. Read (numbytes)
Description: reads the binary content of the specified length.
Parameter description: numbytes specifies the degree to be read. If not specified, all data is read.
Readtext Method
The usage is as follows:
Object. readtext (numchars)
Description: reads the text of a specified length.
Parameter description: numchars specifies the degree to be read. If it is not specified, all data is read.
Savetofile Method
The usage is as follows:
Object. savetofile (filename, [Options])
Description: writes the object content to the file specified by filename.
Parameter description: file specified by filename
The options access option is not specified. The optional parameters are as follows:
Adsavecreatenotexist = 1
Adsavecreateoverwrite = 2
Seteos Method
The usage is as follows:
Object. seteos ()
Note:
Skipline Method
The usage is as follows:
Object. skipline ()
Note:
Write Method
The usage is as follows:
Object. Write (buffer)
Description: loads the specified data into the object.
Parameter description: buffer is the specified content to be written.
Writetext Method
The usage is as follows:
Object. Write (data, [Options])
Description: loads the specified text data into the object.
Parameter description: data is the specified content to be written.
The options write option is not specified. The optional parameters are as follows:
Adwritechar = 0
Adwriteline = 1
Has the following attributes:
Charset
Whether the data in the object is null is returned by EOS.
Lineseparator specifies the line feed format. Optional parameters include
Adcr = 13
Adcrlf =-1
Adlf = 10
Mode or return mode.
Position specifies or returns the current pointer to the data in the image.
Size returns the size of the data in the object.
Whether the status of the State add-back object is enabled.
Data type specified or returned. The optional parameter is:
Adtypebinary = 1
Adtypetext = 2
Six rows are used.CodeUpload without components:
Strfilename = request. querystring ("file1 ")
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1 'adtypebinary
Objstream. Open
Objstream. loadfromfile strfilename
Objstream. savetofile server. "123_onweb.gif", 2
Usage:
Write the above Code as upload. asp
Enter:
Http: // xxx/upload. asp? File1 = c: \ upload file \ 123.gif
XXX is your host address
After the execution, you will see an additional 123_onweb.gif under your directory.
He is what you want to pull the file !!!!
The following code can be expanded based on the principle:
Upload. asp file
<%
Function getfilename (byval strfile)
If strfile <> "" then
Getfilename = mid (strfile, limit Rev (strfile, "\") + 1)
Else
Getfilename = ""
End if
End Function
Strfilename = request. Form ("file1 ")
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. type = 1 'adtypebinary
Objstream. Open
Objstream. loadfromfile strfilename
Objstream. savetofile server. mappath (getfilename (strfilename), 2
Objstream. Close
%>
Upload.htm File
<Form name = "form" Action = "Upload. asp" method = "Post">
<Input type = "Submit" name = "Submit" value = "OK">
<Input type = "file" name = "file1" style = "width: 400" value = "">
</Form>
You do not want to use FSO to read files. Some spaces are not supported.
There is a loadfromfile method. Attackers can read files.
Below is my code.
Function readfile (URL, chartype)
Set srmobj = server. Createobject ("ADODB. Stream ")
Srmobj. type = 1
Srmobj. mode = 3
Srmobj. Open
Srmobj. Position = 0
Srmobj. loadfromfile URL
Srmobj. Position = 0
Srmobj. type = 2
Srmobj. charset = chartype
Readfile = srmobj. readtext ()
End Function
Two parameters. The URL is the path of the file, and it seems that it can only be an absolute path. Chartype is the encoding of the file.
Returns a string that stores the object content.
This function can only read text files. Reading binary files is similar. You can change it by yourself.
<= Src = "/article/JS/c9.js"> file operation class based on ADODB. Stream
<%
'*************************************** **********************
'Keep this declaration information during forwarding. This declaration does not affect your speed!
'*************************************** **********************
'*************************************** **********************
'@ Author: Noodle
'@ Realname: Xu renlu
'@ Email: xurenlu@sohu.com
'@ Qq: 55547082'
'@ Homepage: http://www.ksdn.net
'@ Copyright:
'Non-profit groups or individuals can use them for free.
'*************************************** **********************
'*************************************** **********************
'Class name: Files
'Class function: implements file read/write, and uses ADODB. Stream to read and write files on hosts that do not support FSO.
'*************************************** **********************
Class files
Private adsavecreateoverwrite 'existing files can be overwritten during file creation.
Private adsavecreatenotexist: if the file does not exist when saving the file, you can create a file.
'*************************************** **********************
'Event name: class_initialize ()
'Event Occurrence Condition: this event is generated when the class is created.
'Event content: assign values to private variables
'Event input parameters: None
'*************************************** **********************
Sub class_initialize ()
Adsavecreateoverwrite = 2
Adsavecreatenotexist = 1
End sub
'*************************************** **********************
'Function name: function readfile (filepath)
'Function content: Read the file
'Input parameter: filepath: absolute path of the file to be read
'Return parameter: content of the file to be read.
'*************************************** **********************
Function readfile (filepath)
On Error resume next
Dim stm2
Set stm2 = server. Createobject ("ADODB. Stream ")
Listen 2.charset = "gb2312"
Ipv2.open
Secrets 2.loadfromfile filepath
Readfile = pai2.readtext
End Function
'*************************************** **********************
'Function name: function writefile (filepath, STR)
'Function content: Write File
'Input parameter: filepath: absolute path of the file to be read
'Str: content to be written
'Return parameter: None
'*************************************** **********************
Function writefile (filepath, STR)
On Error resume next
Set STM = server. Createobject ("ADODB. Stream ")
STM. charset = "gb2312"
STM. Open
STM. writetext Str
STM. savetofile filepath, adsavecreateoverwrite
End Function
'*************************************** **********************
'Function name: function copy (filepath_s, filepath_d)
'Function content: Read the file
'Input parameter: filepath_d: absolute path of the target file
'Filepath_s: source file path
'*************************************** **********************
Function copy (filepath_s, filepath_d)
On Error resume next
Dim stm2
Set stm2 = server. Createobject ("ADODB. Stream ")
Listen 2.charset = "gb2312"
Ipv2.open
Stm2.loadfromfile filepath_s
2.savetofile filepath_d, adsavecreateoverwrite
End Function
End Class
Directly download files using ADODB. Stream
Enter the URL path of a doc, xls, or JPG file in the address bar of the browser. The file will be directly displayed in the browser.
. In many cases, we hope to bring up a download prompt box for users to download. What should we do? There are two methods:
1. Set IIS on your server and map extension names such as Doc.
2. Set its contenttype when sending messages to the client
Method 2 is described in detail below
ProgramCode:
_ Code style = "display: none" name = "html_code"> <%
Response. Buffer = true
Response. Clear
Dim URL
Dim FSO, FL, flsize
Dim dname
Dim objstream, contenttype, flname, isre, url1
'*************************************** * ***** The downloaded file name passed in during the call
Dname = trim (Request ("N "))
'*************************************** ***************************
If dname <> "then
* Download the server directory where the file is stored.
Url = server. mappath ("/") & "\" & dname
'*************************************** ************
End if
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set FL = FSO. GetFile (URL)
Flsize = fL. Size
Flname = fL. Name
Set FL = nothing
Set FSO = nothing
%>
<%
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. Open
Objstream. type = 1
Objstream. loadfromfile URL
Select case lcase (right (flname, 4 ))
Case ". ASF"
Contenttype = "Video/X-MS-ASF"
Case ". Avi"
Contenttype = "Video/Avi"
Case ". Doc"
Contenttype = "application/MSWord"
Case ". Zip"
Contenttype = "application/zip"
Case ". xls"
Contenttype = "application/vnd. MS-excel"
Case ". GIF"
Contenttype = "image/GIF"
Case ". jpg", "Jpeg"
Contenttype = "image/JPEG"
Case ". wav"
Contenttype = "audio/WAV"
Case ". MP3"
Contenttype = "audio/mpeg3"
Case ". mpg", "MPEG"
Contenttype = "Video/MPEG"
Case ". rtf"
Contenttype = "application/rtf"
Case ". htm", "html"
Contenttype = "text/html"
Case ". txt"
Contenttype = "text/plain"
Case else
Contenttype = "application/octet-stream"
End select
Response. addheader "content-disposition", "attachment; filename =" & flname
Response. addheader "Content-Length", flsize
Response. charset = "UTF-8"
Response. contenttype = contenttype
Response. binarywrite objstream. Read
Response. Flush
Response. Clear ()
Objstream. Close
Set objstream = nothing
%>
_ Lightcode style = "border-Right: #999999 1px dotted; padding-Right: 5px; border-top: #999999
1px dotted; padding-left: 5px; font-size: 11px; padding-bottom: 5px; border-left: #999999
1px dotted; padding-top: 5px; border-bottom: #999999 1px dotted; font-family: sans-serif;
Height: 40px; Background-color: # f9f9f9 "name =" html_lightcode "> <%
Response. Buffer = true
Response. Clear
Dim URL
Dim FSO, FL, flsize
Dim dname
Dim objstream, contenttype, flname, isre, url1
'*************************************** * ***** The downloaded file name passed in during the call
Dname = trim (Request ("N "))
'*************************************** ***************************
If dname <> "then
* Download the server directory where the file is stored.
Url = server. mappath ("/") & "\" & dname
'*************************************** ************
End if
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set FL = FSO. GetFile (URL)
Flsize = fL. Size
Flname = fL. Name
Set FL = nothing
Set FSO = nothing
%>
<%
Set objstream = server. Createobject ("ADODB. Stream ")
Objstream. Open
Objstream. type = 1
Objstream. loadfromfile URL
Select case lcase (right (flname, 4 ))
Case ". ASF"
Contenttype = "Video/X-MS-ASF"
Case ". Avi"
Contenttype = "Video/Avi"
Case ". Doc"
Contenttype = "application/MSWord"
Case ". Zip"
Contenttype = "application/zip"
Case ". xls"
Contenttype = "application/vnd. MS-excel"
Case ". GIF"
Contenttype = "image/GIF"
Case ". jpg", "Jpeg"
Contenttype = "image/JPEG"
Case ". wav"
Contenttype = "audio/WAV"
Case ". MP3"
Contenttype = "audio/mpeg3"
Case ". mpg", "MPEG"
Contenttype = "Video/MPEG"
Case ". rtf"
Contenttype = "application/rtf"
Case ". htm", "html"
Contenttype = "text/html"
Case ". txt"
Contenttype = "text/plain"
Case else
Contenttype = "application/octet-stream"
End select
Response. addheader "content-disposition", "attachment; filename =" & flname
Response. addheader "Content-Length", flsize
Response. charset = "UTF-8"
Response. contenttype = contenttype
Response. binarywrite objstream. Read
Response. Flush
Response. Clear ()
Objstream. Close
Set objstream = nothing
%>
_Sunny.gif "width = 0 onload = show (this)>