當前位置:首頁 » 存儲配置 » 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中怎麼將圖片存入資料庫,在取出

目前圖片存入資料庫有兩種方法,第一是先把圖片上傳到一個制定目錄,然後把它的路徑存入資料庫,另一種是把圖片變成
二進制編碼
,直接把這個編碼寫入數據里。如果是變換的圖片,肯定要用數據里啊

熱點內容
mysql上傳圖片php 發布:2024-10-07 04:13:31 瀏覽:852
手游喊話腳本 發布:2024-10-07 03:53:53 瀏覽:232
maven3編譯jdk6項目 發布:2024-10-07 03:19:57 瀏覽:45
緩存的視頻無法剪輯 發布:2024-10-07 03:19:40 瀏覽:89
解壓工具RAR 發布:2024-10-07 02:42:49 瀏覽:353
蘋果網盤解壓 發布:2024-10-07 02:42:49 瀏覽:160
為什麼安卓蘋果手游不互通 發布:2024-10-07 02:31:28 瀏覽:281
如何刪除手機中的游戲緩存 發布:2024-10-07 02:11:28 瀏覽:876
解鎖資料庫用戶 發布:2024-10-07 01:55:54 瀏覽:828
關系資料庫的關鍵字是指 發布:2024-10-07 01:55:54 瀏覽:520