Easy implementation of ASP to upload pictures to the database code _ Application Skills
Source: Internet
Author: User
Easy implementation will upload pictures to the database
Long time I want to write a program, but because Lai did not want to write me, today is just free, so write this small program is easy to see it, not much to say this start:
Let's do an upload. The field of the data base is automatically numbered with the ID big field type is OLE oh on the simple that field okay
uppic.asp Upload Program Name
<%
Dim rs
Dim formsize,formdata,bncrlf,divider,datastart,dataend,mydata
Formsize=request.totalbytes ' Gets the size of the client sent over
Formdata=request.binaryread (formsize) ' The data sent from the customer into binary production
BNCRLF=CHRB (+) & ChrB (10)
Divider=leftb (FORMDATA,CLNG (INSTRB (FORMDATA,BNCRLF))-1)
DATASTART=INSTRB (Formdata,bncrlf & Bncrlf) +4
DATAEND=INSTRB (Datastart+1,formdata,divider)-datastart
MYDATA=MIDB (formdata,datastart,dataend) ' above is to get the binary data of the picture
%>
<!--#include file= "conn.asp"-->
<%
Sql= "SELECT * from pic-id DESC"
Set rs = Server.CreateObject ("ADODB.") Recordset ")
Rs. Open sql,conn,3,2
Rs.addnew
RS ("Big"). AppendChunk MyData ' added to the database
Rs.update
Set rs=nothing
Set conn=nothing
%>
Next is the display picture
Display.asp
<!--#include file= "conn.asp"--> "This is what everyone knows, he's a database-linked program.
<%
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" shows the format of the picture can also be used
' Response.ContentType = ' image/gif ' in GIF display
' Response.ContentType = ' image/jpg ' is shown in JPG
Response.BinaryWrite RS ("big") ' Show pictures
Rs.close
Set rs=nothing
Set conngraph=nothing
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.