Write a website application with ASP, it is difficult to encounter a wide range of questions, where to upload files to the server, I am probabulous to meet the most problems, especially upload pictures, such as what you want in your own community. Realize the "Daily One Star" functionality provided by Netease Virtual Community, it is necessary to provide users' ability to upload photos. Upload image files to the server can use a variety of free file upload components, which is very powerful, but because in many cases, we can only use the free support ASP space or rent different virtual space for the first situation. We have no possibility to use file upload components; as for the second case, we have to pay a lot of "silver". Unless you have your own virtual host, you can just install your own components on the server, this situation is desirable for most people. Then there is no way? Oh, the answer is sure (of course, it is certain, or I can't write this article). Let's use the pure ASP code to implement the upload of the picture and save to the database. First let's first familiarize yourself with the object method to use. The data we use to get the previous page is generally used to use the Request object. Similarly, we can also use the REQUEST object to get uploaded file data, and the method used is request.binaryRead (). The data we have to read from the database is displayed to the method you want to use on the web page is: request.binaryWrite (). When we get the picture of the picture, when you want to save to the database, you cannot use the INSERT statement to operate directly using the ADO's Appendchunk method, the same, read the image data in the database, to use Getchunk method. The specific syntax of each method is as follows: * Request.binaryRead Syntax: Variant = Request.binaryRead (count) Parameter Variant Return Value saves to read the data from the client. Count indicates the amount of data to be read from the client, which is less than or equal to the amount of data obtained by using the method Request.Totalbytes. * Request.binaryWrite Syntax: Request.BinaryWriteData Parameters Data To write to the packet in the client browser. * Request.totalbytes syntax: variant = request.totalbytes parameter Variant Returns the number of bytes from the client to the amount of data. * Appendchunk syntax adds data to large text, binary data field or parameter object. Object.AppendchunkData Parameters ObjectField or Parameter object DATA variable body, contains data added to the object. Note The Appendchunk method using the field or parameter object can be filled in the object in the object. In the case where the system is limited, the Appendchunk method can be used to partially perform a portion rather than all operations. * Getchunk syntax returns all or part of the large text or binary data Field object. Variable = field.getchunk (size) Return value return variant. Parameter size long integer expressions, equal to the number of bytes or characters to be retrieved. Note The GetChunk method using the Field object retrieves its part or all long binary or character data. In the case where the system is limited, the GetChunk method can be used to handle the portion instead of all long integer values. The data returned by the getChunk call will assign it to the "variable".
If size is greater than the remaining data, getChunk only returns the remaining data without populating the "variable" with a blank. If the field is empty, the getChunk method returns NULL. Each subsequent GetChunk call will retrieve data starting from the previous GetChunk call stop. However, if the data is retrieved from a field and then set or read in the current record, the ADO will consider the data from the first field. If the getchunk method is called again on the first field, the ADO will interpret the call as a new GetChunk operation and start reading from the beginning of the record. If other Recordset objects are not a copy of the first RECORDSET object, the fields that are accessed do not destroy the getChunk operation. If the Adfldlong bit in the Attributes property of the Field object is set to True, you can use the getChunk method for this field. If there is no current record when using a getchunk method on the field object, an error 3021 (no current record) is generated. Next, we have to design our database, as a test of our database structure (Access2000): Field Name Type Description ID Auto Number Main key value IMG OLE object is used to save image data For MSSQLSERVER7, the corresponding structure As follows: Field Name Type Description ID INT (Identity) Primary key value IMG image Used to save image data Now officially preparing our pure ASP code upload section, first, we have an upload interface that provides users, allowing users to choose To upload the picture. The code is as follows: