当前位置:首页 » 存储配置 » asp图片存储数据库

asp图片存储数据库

发布时间: 2022-07-21 23:44:56

❶ asp如何将图片以二进制方式存如数据库。非form方式

可以试试用ADODB.Stream这个组件,这是ADO默认安装的,大多数ASP空间都支持的一个组件.
该组件支持二进制文件的读写操作,可以试试.
Set aso = CreateObject("ADODB.Stream")
aso.Mode = 3
aso.Type = 1
aso.Open
aso.LoadFromFile("文件的本地路径")
bstr = aso.Read(-1)
aso.Close
Set aso = Nothing
bstr 即为二进制内容.

❷ 如何用ASP实现多处图片上传并保存到数据库中

网页上传图片多数不是把图片保存在数据库,是将图片文件放在一个建好的目录,上传的时候,字段里只保存图片的路径。
上传多张图片,用FOR循环

❸ 用asp如何将图片存入后台数据库

<form action="News.asp?act=savenew" method="POST" name="newsadd" onSubmit="return CheckForm();">
<table width="95%" border="0" cellspacing="1" cellpadding="3" bgcolor="#cccccc" align="center">

<tr bgcolor="#EEEEEE">
<td align="right"><strong>新闻图片:</strong></td>
<td bgcolor="#EEEEEE">
<iframe border="0" frameBorder="0" frameSpacing="0" height="21" marginHeight="0" marginWidth="0" noResize scrolling="no" width="100%" vspale="0" src="NewsUpload.asp"></iframe><br>
<input name="pic1" id="pic1" size="40" maxlength="200"></td>
</tr>
<tr bgcolor="#ffffff">
<td align="right" bgcolor="#EEEEEE"> </td>
<td colspan="2" bgcolor="#EEEEEE"><input name="Add" type="submit" id="Add" value=" 添 加 "></td>
</tr>
</table>

❹ asp.net mvc 上传照片保存到数据库

照片存到数据库,有两种方式,一种直接图片转成二进制文件存到数据库,另一种将图片放在服务器指定文件中,在数据库中存储图片物理路径,如果图片较多,建议存图片对应物理路径

❺ 如何用asp.net把上传的图片保存到数据库中

数据库里面用binary保存二进制流
图片你就转换成byte[]就可以了
不建议把图片保存到数据库里面
那样你的数据库会占用很大的磁盘空间
等数据量一大
就很卡

❻ 在ASP中,如何把图片和文字同时保存到数据库中,并在需要时同时输出。

  • 假设有这样一个表单。

  • <form id="myform" enctype="multipart/form-data" action="upload.asp" method="post">

  • <input type="file" name="file1"><!-用于提交文件,既图片文件-->

  • <input type="text" name="mytext"><!-用于提交文字信息-->

  • <input type="submit" name="tj" value="提交"><!--表单提交按钮-->

  • </form>

  • 表单能提交图片,也能提交文字。内容提交到upload.asp去处理。下面是upload.asp里面的部分内容。

  • <%Response.Charset="utf-8"%>

  • <%

  • '查询字符串thisstr2在字符串thisstr1里面第N次出现的位置,如果没有出现,返回空。

  • '这个函数也很有用。比如获得文件名的时候,文件名 name="file1" filename="abc.jpg",先二进制转文本,然后找到双引号第三次出现的位置和第四次出现的位置,两个位置中间的内容就是文件名,还可以得到文件的扩展名"jpg"

  • function strN(thisN,thisstr1,thisstr2)

  • thistemp=1

  • for thiss=1 to len(thisstr1)

  • thisdatastart=instr(thistemp,thisstr1,thisstr2)

  • if thisdatastart=0 or thisdatastart=null then

  • exit for

  • end if

  • if thisdatastart<>0 or thisdatastart<>null then

  • thistemp=thisdatastart+len(thisstr2)

  • thiscishu=thiscishu+1

  • if thiscishu=thisN then

  • strN=thisdatastart

  • exit for

  • end if

  • end if

  • next

  • if thiscishu<thisN then

  • strN=""

  • end if

  • end function

  • '查询二进制数据流thisstr2在thisstr1里面出现的次数。这个函数在已知表单提交信息条数的情况下就用不到。但如果是表单提交的信息条数未知,比如批量上传图片的时候,不知道有多少个type="file"的input,就需要用这个函数先判断一下。既判断分割符在提交数据里面出现的次数。出现了n次则有n-1条数据提交。

  • function mynumberb(thisstr1,thisstr2)

  • thistemp=1

  • for thisn=1 to len(thisstr1)

  • thisdatastart=instrb(thistemp,thisstr1,thisstr2)

  • if thisdatastart=0 or thisdatastart=null then

  • exit for

  • end if

  • if thisdatastart<>0 or thisdatastart<>null then

  • thistemp=thisdatastart+len(thisstr2)

  • thiscishu=thiscishu+1

  • end if

  • next

  • mynumberb=thiscishu

  • end function

  • '查询二进制数据流thisstr2在thisstr1里面第thisN次出现的位置,如果没有出现,返回空。

  • '这个函数很有用,比如表单传过来的数据都是用回车换行符号隔开的。只需要查询回车换行符号第4次出现的位置和第五次出现的位置,就能找到文件二进制数据开始和结束的位置。如果表单发送过来的是文本信息,只需要找到回车换行符号第三次出现的位置和第四次出现的位置,就能找到文本的二进制数据。然后二进制转文本,就提取出文本内容了。

  • function strNb(thisN,thisstr1,thisstr2)

  • thistemp=1

  • for thiss=1 to len(thisstr1)

  • thisdatastart=instrb(thistemp,thisstr1,thisstr2)

  • if thisdatastart=0 or thisdatastart=null then

  • exit for

  • end if

  • if thisdatastart<>0 or thisdatastart<>null then

  • thistemp=thisdatastart+len(thisstr2)

  • thiscishu=thiscishu+1

  • if thiscishu=thisN then

  • strNb=thisdatastart

  • exit for

  • end if

  • end if

  • next

  • if thiscishu<thisN then

  • strNb=""

  • end if

  • end function

  • '二进制转文本

  • Function stb(vin)

  • const adTypeText=2

  • dim BytesStream,StringReturn

  • Set BytesStream=Server.CreateObject("ADODB.Stream")

  • with BytesStream

  • BytesStream.Type=adTypeText

  • BytesStream.Open

  • BytesStream.WriteText vin

  • BytesStream.Position=0

  • BytesStream.Charset="utf-8"

  • BytesStream.Position=2

  • StringReturn=BytesStream.ReadText

  • BytesStream.Close

  • end with

  • set BytesStream=Nothing

  • stb=StringReturn

  • end function

  • '以上几个函数介绍完毕。接下来就是实际处理表单提交的信息了。

  • response.buffer=true

  • formsize=request.totalbytes

  • formdata=request.binaryread(formsize)

  • hcf=chrB(13)&chrB(10)'回车换行符号

  • fgf=leftB(formdata,clng(instrb(formdata,hcf))-1)'分隔符

  • cd=lenb(fgf)'分割符的长度

  • '截取第一条数据,既文件数据。

  • mydatastart=strnb(1,formdata,fgf)+cd

  • mydataend=strnb(2,formdata,fgf)-1

  • mydatasize=mydataend-mydatastart+1

  • formdata1=midb(formdata,mydatastart,mydatasize)'第一条提交的数据信息,既第一个type=file的图片文件

  • '得到文件的名字

  • mytempdata=stb(formdata1)

  • mydatastart=strn(3,mytempdata,"""")+1'双引号第三次出现的位置加1就是文件名出现的开始位置

  • mydataend=strn(4,mytempdata,"""")-1'双引号第四次出现的位置就是文件名结束的位置

  • mydatasize=mydataend-mydatastart+1

  • wjfilename=mid(mytempdata,mydatastart,mydatasize)'得到文件名字,就是提交的那个图片的名字,比如"myimg.jpg"

  • '截取图片文件的二进制数据

  • mydatastart=strnb(4,formdata1,hcf)+2'回车符号第四次出现的位置加2就是图片文件的二进制数据开始的位置

  • mydataend=strnb(5,formdata1,hcf)-1'回车符号第五次出现的位置减1就是图片二进制数据结束的位置

  • mydatasize=mydataend-mydatastart+1'图片文件二进制数据的长度

  • wjdata=midb(formdata1,mydatastart,mydatasize)'得到图片文件的二进制数据

  • '截取第二条数据,既截取提交的文本二进制数据

  • mydatastart=strnb(2,formdata,fgf)+cd

  • mydataend=strnb(3,formdata,fgf)-1

  • mydatasize=mydataend-mydatastart+1

  • formdata2=midb(formdata,mydatastart,mydatasize)'第二条提交的数据信息,既提交的文字信息。

  • '提取文本

  • mydatastart=strnb(3,formdata2,hcf)+2

  • mydataend=strnb(4,formdata2,hcf)-1

  • mydatasize=mydataend-mydatastart+1

  • wbdata=midb(formdata2,mydatastart,mydatasize)

  • wb=stb(wbdata)

  • '到此,表单信息全部接收完毕。

  • 'wjfilename:文件名。

  • 'wjdata:文件二进制数据。

  • 'wb:文字信息。

  • '下面要做的就是把文本信息存入数据库。把文件的二进制数据转换成图片存入文件夹,也可以直接二进制数据存放到数据库里面。

  • '至于怎么存放路径等一系列问题,这些都是简单问题。最难啃的骨头已经啃完了。

  • '文件信息存入文件夹提供一种思路,这种思路比较简单。

  • 'access里面的temp字段是存储二进制数据的,表名也叫temp

  • 'call conn_open(conn,"xxx.mdb")打开access

  • 'sql="select * from temp"

  • 'call rs_open3(rs,sql)打开表

  • ' rs.addnew

  • ' rs("temp").appendchunk wjdata

  • ' rs.update

  • ' Set MyStream=Server.CreateObject("Adodb.Stream")

  • ' MyStream.Type=1

  • ' MyStream.Open

  • ' MyStream.Write rs("temp").getChunk(8000000) 把数据库里面的图片读出来

  • '得到图片上传的日期时间连接1到1000之间的随机数做图片的名字,把时间里面的左斜杠,冒号以及空格都替换掉。

  • ' picName=replace(now(),"/","")

  • ' picName=replace(picName,":","")

  • ' Randomize

  • ' picName=replace(picName," ","")&Int((1000 * Rnd) + 1)

  • ' MyStream.SaveToFile server.mappath("img/"&picName&".jpg")

  • '把图片存入目录,注意,这里如果事先前端做了判'断用户提交的图片就必定是"jpg"格式,所以可以直接用。如果前端没做判断,就用刚'才得到的split(wjfilename,".")(1)作为扩展名。这玩意儿能看懂吧,wjfilename里面保存的是图片名字"abcd.jpg",用"."分割,

  • '后面的那个就是"jpg"图片扩展名

  • ' MyStream.close

  • ' set MyStream=nothing

  • 'call rs_close(rs)关闭表

  • 'call conn_close(conn)关闭access

  • %>

    以上提供的思路既然可以图片文字一起提交,也可以在不知道表单提交数据条数的情况下批量混合提交图片和文字信息。原理是死的,人的思路是活的。活学活用最好。

❼ asp怎么实现图片存入数据库

图片上传到放图片的文件夹,数据库中只用放图片相对路径。
一般图片无组件上传用
upload_5xsoft.inc文件:
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_5xSoft_Stream

Class upload_5xSoft

dim Form,File,Version

Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="21gt.com上传程序v1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=nothing
End Sub

Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.to dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>
调用样式:
<!--#include file="conn.asp" -->
<!--#include file="upload_5xsoft.inc" -->
<%
if request("action")="addpic" then
set upload=new upload_5xSoft
set file=upload.file("file1")
formPath="../xiangce/"
formpath1="xiangce/"
if file.filesize>100 then
fileExt=lcase(right(file.filename,3))
if fileExt="asp" then
Response.Write"文件类型非法"
end if
end if
randomize
ranNum=int(90000*rnd)+10000
filename0=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
filename=formPath&filename0
filename1=formpath1&filename0
if file.FileSize>0 then
file.SaveAs Server.mappath(FileName)
end if
response.write "图片上传成功,[<a href='picture.asp?pic_url="&filename1&"'>返回填写图片名称和主题</a>]"
else
set upload=new upload_5xSoft
set file=upload.file("file1")
formPath="newimage/"
if file.filesize>100 then
fileExt=lcase(right(file.filename,3))
if fileExt="asp" then
Response.Write"文件类型非法"
end if
end if
randomize
ranNum=int(90000*rnd)+10000
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&fileExt
if file.FileSize>0 then
file.SaveAs Server.mappath(FileName)
end if
response.write "图片上传成功"
end if
%>
传值的表单用文件类型。

❽ asp中怎么将图片存入数据库,在取出

目前图片存入数据库有两种方法,第一是先把图片上传到一个制定目录,然后把它的路径存入数据库,另一种是把图片变成
二进制编码
,直接把这个编码写入数据里。如果是变换的图片,肯定要用数据里啊

热点内容
c语言读程序题 发布:2024-05-19 10:13:52 浏览:674
新的安卓手机怎么样下载微信 发布:2024-05-19 10:05:06 浏览:878
加9的算法 发布:2024-05-19 10:04:15 浏览:263
新名图配置怎么样 发布:2024-05-19 09:31:30 浏览:94
php获取子节点 发布:2024-05-19 09:21:18 浏览:160
php生成html 发布:2024-05-19 09:20:24 浏览:795
keil编译步骤 发布:2024-05-19 08:58:12 浏览:702
ipad有哪些好用的c语言编译器 发布:2024-05-19 08:41:56 浏览:767
征途手游版脚本 发布:2024-05-19 08:38:11 浏览:165
安卓咪咕音乐怎么录制视频 发布:2024-05-19 07:56:06 浏览:838