Home >Backend Development >C#.Net Tutorial >asp saves binary images to access database

asp saves binary images to access database

PHP中文网
PHP中文网Original
2017-08-26 09:58:432582browse

This article is provided by PHP Chinese website and introduces how to use asp to upload binary images and save them to the access database.

The specific implementation code is as follows:

Save image user upload page (3.asp):

<html>
<body>
<center>
   <form name="mainForm" enctype="multipart/form-data" action="2.asp" method=post>
   <input type=file name=mefile><br>
   <input type=submit name=ok value="OK">
   </form>
</center>
</body>
</html>


Save image page (2.asp) asp):

<%
response.buffer=true
formsize=request.totalbytes
formdata=request.binaryread(formsize)
bncrlf=chrB(13) & chrB(10)
pider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,pider)-datastart
mydata=midb(formdata,datastart,dataend)set connGraph=server.CreateObject("adodb.connection")
connGraph.open"provider=microsoft.jet.oledb.4.0;data source=E:\PHP\valve.mdb;"
set rec=server.createobject("ADODB.recordset")
rec.Open "SELECT * FROM [user]",connGraph,1,3
rec.addnew
rec("img").appendchunk mydata
rec.update
rec.close
set rec=nothing
set connGraph=nothing
%>




Image reading page (1.asp): This page does not allow html code, otherwise garbled characters will appear!

<%
set rs=server.createobject("ADODB.recordset")
sql=""
rs.open strsql,connGraph,1,1
Response.ContentType = "image/*"
Response.BinaryWrite rs("").getChunk(8000000)
%>

The number in getChunk() must be greater than or equal to the number of bytes of the image to be displayed, otherwise the image will not be displayed completely!


Image display page (4.asp):

<html>
<body>
<img src="1.asp?id=要显示的图片id">
</body>
</html>

Article address: http://www.php.cn/csharp-article-377483.html

Come to PHP Chinese website to learn programming www.php.cn

~~~~

The above is the detailed content of asp saves binary images to access database. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn