Someone posted a component-free upload program using ado stream. Today I will give a brief introduction to it.
In the past, if you wanted to use ASP to operate files, such as moving, copying, deleting, or creating a notepad file, it was basically done through the FILESYSTEMOBJECT object. Of course, this is very professional, it provides complete file information, such as the creation time, size, and last modification time. However, if you do not make a painful and costly conversion of character formats, using it, you cannot directly operate binary files.
However, the stream object we introduced can operate both the Text object and binary object, which requires that ADO2 is installed on your machine. 5 or later, you can download from http://www.microsoft.com/data.
This stream object contains many methods for operating binary and text files. Let's take a look at the example.
Open stream Object
<! -- Metadata type = "typelib" UUID = "00000205-0000-0010-8000-00AA006D2EA4" NAME = "ADODB Type Library" --> <% 'create a Stream instanceDim objStreamSet objStream = Server. createObject ("ADODB. stream ") 'Open the streamobjStream. open
If you do not understand the above references, you can refer to the post I posted earlier.
Note: If the version is incorrect, an error message is displayed.
Now you have created a STREAM with a length of 0. At any time, you can use the size attribute to change the stream size. Now we need to specify the type of operation information, binary or text, if it is text, you must specify the ASCII or UNICODE format.
The following code:
ObjStream. Type = adTypeText
ObjStream. Charset = "ascii"
Next, we will write a text file into this stream and use its loadfromfile method.
ObjStream. LoadFromFile "D: \ Inetpub \ wwwroot \ webtech \ 083100-1.shtml"
Note that if you operate stream, you must understand the concept of location. Here, after using the loadfromfile method, all content in the original stream will be cleared. Then, the file is loaded into the stream, and the stream position is restored to 0 (the starting position of the stream)
If you write information at the current zero position, the original content will be overwritten. Therefore, if you want to append an object, you must start from the last position. The following code:
ObjStream. Position = objStream. Size
This code moves the current position to the end
Now we can add something to the back, hey, for example
ObjStream. WriteText "please visit my chat room, especially MM"
Haha
Now we have achieved our goal. Let's save it.
Note that because you use an iuser_machinename account, you must open the write permission to the account in the corresponding directory. Otherwise, an error may occur.
ObjStream. SaveToFile "D: \ InetPub \ wwwroot \ demos \ StreamDemo.txt", adSaveCreateOverwrite
Inherit from our excellent tradition, and close release after use
'Close the stream and set it to nothing...
ObjStream. Close
Set objStream = Nothing
%>
As I mentioned earlier, it can also operate binary objects. In fact, you only need to modify some parameters. Let's look at an example:
<! -- Metadata type = "typelib"
UUID = "00000205-0000-0010-8000-00AA006D2EA4"
NAME = "ADODB Type Library"
-->
<%
'Create a stream object
Dim objStream
Set objStream = Server. CreateObject ("ADODB. Stream ")
'Open a GIF file
ObjStream. Type = adTypeBinary
ObjStream. Open
ObjStream. LoadFromFile "D: \ Inetpub \ wwwroot \ images \ banner \ dimacbanner1.gif"
'Output the contents of the stream object
Response. ContentType = "image/gif"
Response. BinaryWrite objStream. Read
'Clean up ....
ObjStream. Close
Set objStream = Nothing
%>
You can try to use this to write an upload object so that you can learn it quickly. There are ready-made teachers. For more information, see
Hope to help you, by the way, my chat room is http://www.sanchat.com, do not forget to join ah !!!