ASP allows you to easily upload images to a database.

Source: Internet
Author: User

Allows you to easily upload images to a database.

I want to write it myself for a long timeProgramBut I don't want to write it to me. Today is just free, so it's easy to get started with this small program:

Let's make an upload. The field ID of the data database is automatically numbered. The big field type is Ole.

Uppic. asp upload program name

<%
Dim rs
Dim formsize, formdata, bncrlf, divider, datastart, dataend, mydata
Formsize = request. totalbytes 'Get the size sent from the client
Formdata = request. binaryread (formsize) 'converts the data sent by the customer into binary
Bncrlf = chrb (13) & chrb (10)
Divider = leftb (formdata, clng (partition B (formdata, bncrlf)-1)
Datastart = instrb (formdata, bncrlf & bncrlf) + 4
Dataend = Consumer B (datastart + 1, formdata, divider)-datastart
Mydata = midb (formdata, datastart, dataend) 'above is a total of binary data obtained from the image

%>
<! -- # Include file = "conn. asp" -->
<%
SQL = "select * from PIC order by ID DESC"
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 3, 2
Rs. addnew
RS ("big"). AppendChunk mydata is added to the database.
Rs. Update
Set rs = nothing
Set conn = nothing
%>
Next, display the image.

Display. asp

<! -- # Include file = "conn. asp" --> 'Everyone knows that he is a program connected to the database.
<%
Id = request ("ID ")
Set rs = server. Createobject ("ADODB. recordset ")
SQL = "select * from PIC where id =" & ID
Rs. Open SQL, Conn, 1, 1
Response. contenttype = "text/html" 'the format of the displayed image can also be used

'Response. contenttype = "image/GIF" displayed as GIF

'Response. contenttype = "image/jpg" displayed as JPG
Response. binarywrite RS ("big") 'show image
Rs. Close
Set rs = nothing
Set conngraph = nothing

%>

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.