Using pure ASP code to upload and store the picture in the database (i)

Source: Internet
Author: User
Tags file upload
Using ASP to write Web applications for a long time, will inevitably encounter a variety of problems, including on how to upload files to the server I am afraid to meet the most problems, especially upload pictures, such as you want to achieve in their own community similar to the NetEase virtual community to provide a "Daily Star" function, It is necessary to provide users with the ability to upload photos. Upload image files to the server can use a variety of free file upload components, although the function is very powerful, but because in many cases, we can only use the free space to support ASP or rent other people's virtual space, for the first case, we simply do not have the possibility to use the File Upload component As for the second case, we have to pay a lot of "silver" to do so. Unless you have a virtual host of your own, you can easily install the components you need on the server, which is impossible for most people. So there's no way we can do that? Oh, the answer is yes (certainly, or I can not write this article AH). Let's take a look at it. Use pure ASP code to achieve the upload of pictures and save to the database function (incidentally also realize the display database of pictures to the Web page function).
First, let's familiarize ourselves with the object method that will be used. The data we use to get the last page passed over is typically used by the request object. In the same way, we can use the request object to get the uploaded file data, using the Request.BinaryRead (). And we want to read out of the database from the image of the data displayed on the page to use the method is:
Request.binarywrite (). When we get the picture data, to save to the database, we can not directly use the INSERT statement to operate the database, but to use the AppendChunk method of ADO, the same, read the image data in the database, to use the GetChunk method. The specific syntax for each method is as follows:
* Request.BinaryRead Syntax:
Variant = Request.BinaryRead (count)
Parameters
Variant
The return value is stored to read from the client to the data.
Count
Indicates the amount of data to be read from the client, which is less than or equal to the method used
Request.TotalBytes The amount of data obtained.
* Request.binarywrite Syntax:
Request.binarywrite data
Parameters
Data
The packet to write to the client browser.
* Request.TotalBytes Syntax:
Variant = Request.TotalBytes
Parameters
Variant
Returns the number of bytes read from the client to the amount of data.
* AppendChunk Grammar
Appends data to a large text, binary data Field, or Parameter object.
Object. AppendChunk Data
Parameters
Object Field or Parameter objects
The data variant, which contains the information appended to the object.
Description
Use the AppendChunk method of a Field or Parameter object to fill in an object with long binary or character data. In the case of limited system memory, you can use the AppendChunk method to perform partial rather than complete operations on long values.
{not finished!} adjourned
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.