How to use the repository to store your files

Source: Internet
Author: User
Tags html form
In SQL Server, there is a data type for Image, in addition to being able to save a file, it can save a large two-bit data file, for most of the people in this column are heard but do not know how to use, today's article is going to discuss how to deposit the image into the library

Prepare for work

To reduce the length and complexity of this article, I decided to use the Upload component to complete the work on our file, using the Dundas of the money-free, please download the Dundas Upload component at the bottom of the Web site and install

http://www.dundas.com/
Creating Data Sheets

In this case, I'm going to use the SQL library in the Pubs, please open QA and then execute the bottom of the creative data sheet instruction, the data table to be built is a content-type of the record, the other is to save a file

Use Pubs
Create Table Imgdata
(
Imgid Int Identity not Null Primary Key,
ContentType VarChar (20),
Filedata Image
)

HTML form Section

Now look at the part of the HTML form, because it is used as a file to use the enctype= "Multipart/form-data", but note that one but the use of form-data after the acquisition of the form can no longer use Request.Form, Because this is not the point of this article, so do not explain it more, please save the bottom of the password as insert.htm

<title> Data Library to file </title>
<body>
<form method= "POST" enctype= "Multipart/form-data" action= "insert.asp" >
<table border= "0" align= "center" >
<tr>
<td>file:</td>
<td><input type= "File" name= "file" size= "></td>"
</tr>
<tr>
<td></td>
<td><input type= "Submit" value= "on-line" ></td>
</tr>
</table>
</form>
</body>

Code

Stranded to see the part of the Macintosh ASP, please save the bottom of the password into insert.asp

<%
Response.Buffer = True
ConnStr = "Provider=sqloledb;" _
& "Data source= your computer name;" _
& "Initial Catalog=pubs" _
& "User Id=sa" _
& "password= Your password"
' Build Oupload
Set oupload = Server.CreateObject ("Dundas.upload.2")
' Before using the Oupload collection (Collection), call the Save or SaveToMemory method first
Oupload.savetomemory
Set oRs = Server.CreateObject ("Adodb.recordset")
oRS.Open "Imgdata", ConnStr, 2, 3
Ors.addnew
' Call the Oupload object ContentType, Binary, have obtained the information we want
ORs ("ContentType"). Value = oupload.files (0). ContentType
ORs ("Filedata"). Value = oupload.files (0). Binary
Ors.update
Ors.close
Set ORs = Nothing
%>

The top program assumes you only upload one file, so use Oupload.files (0), and if you upload more than one file at a time, you can change the program to

...
oRS.Open ...
For each ofile in Oupload.files
If InStr (1,ofile.contenttype, "image") <> 0 Then
Ors.addnew
ORs ("ContentType"). Value = Ofile.contenttype
ORs ("Imgdata"). Value = Ofile.binary
End If
Next
Ors.update
...

Now you can use the browser to open the insert.htm to the data library's motion, when you are done, you can Select the Imgdata data table, should be a piece of information, but Filedata should not be read!

Today's article is a first introduction to this, the next article to introduce how to pull the image from the library!

Hopefully this article will help you!



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.