Write pictures into Access database

xiaoxiao2021-03-06  44

First, create an Access database: testimg.mdb, the format is as follows:

id

[auto numbering ]

Name

[Text]

IMG

[OLE object]

Size

[Text]

Shouming

[Text]

Type

[Text]

date

[Time / Date]

Then establish the following two files:

Conn.asp

<% db_path = "testimg.mdb"

Set conn = server.createObject ("adoDb.connection")

Connstr = "driver = {Microsoft Access Driver (* .mdb)}; dbq =" & server.mappath (db_path)

Conn.open connStr%>

Showimg.asp

<% set = server.createObject ("adoDb.recordset")

SQL = "SELECT * from imgurl where id =" & trim (Request ("ID"))

RS.Open SQL, CONN, 1, 1

Response.contentType = RS ("Type") '

'Response.addheader "Content-Disposition:", "Attachment; FileName =" & RS ("Name")' This sentence If you open it, all file formats you upload will be identified, and the file name will also be identified. If you don't open, there is only a few file formats to be identified. The file name can not be identified; but there is a sentence to have a short shiver, and there is a profit and cons., So don't open it according to you. The actual situation is ok.

Response.binaryWrite RS ("IMG"). GetChunk (RS ("Size") 10)

Response.end

Rs.close

SET RS = Nothing

SET CONN = NOTHING%>

Establish index.asp. Used to upload files, show what you have uploaded, and its related information: The content is as follows: