⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 实用的图像入库代码.txt

📁 用纯ASP代码实现图片上传并存入数据库中
💻 TXT
字号:
我做的部分代码。    


--------------------------------------------------------------------------------

 【woozhj】 于 2000-06-21 18:34:58 加贴在 Joy ASP ↑  

'二进制数据存入image字段
......
rs.Open SQL,conn,1,3
If rs.Eof Then
   rs.addnew
   ......
   rs("imgcontent").AppendChunk varimgcontent
   rs.Update
......

'显示image图象数据内容的showimage.asp程序
'显示前清除HTTP头信息
Response.Expires = 0
Response.Buffer = TRUE
Response.Clear

......
SQL = "SELECT imgcontent FROM ..."
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open SQL,conn,1,3
If Not rs.Eof Then
   varimgtype = rs("imgtype")
   varfilesize = rs("imgcontent").ActualSize
   varimgcontent = rs("imgcontent").GetChunk(varfilesize)
   Response.ContentType = varimgtype
   Response.BinaryWrite varimgcontent
End If
......

如果是大文本直接用Response.BinaryWrite varimgcontent就可以显示了。





回复:请问如何无组件上传图像?    


--------------------------------------------------------------------------------

 【梦】 于 2000-06-01 13:09:50 加贴在 Joy ASP ↑  

<HTML>
<HEAD><TITLE> File Upload </TITLE></HEAD>
<BODY>

<FORM ENCTYPE="multipart/form-data"
ACTION="uploadresult.asp" METHOD=POST id=form1 name=form1>

Please choose a picture to uploads:
<BR><INPUT NAME="picture" TYPE=FILE ACCEPT="image/gif">
<BR><INPUT TYPE=SUBMIT VALUE="Submit Me!" id=SUBMIT1 name=SUBMIT1>
</FORM>

</BODY>
</HTML>

uploadresult.asp:

<%
FormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )
bnCRLF = chrB( 13 ) & chrB( 10 )
Divider = LEFTB( FormData,  INSTRB( FormData, bnCRLF ) - 1 )
DataStart = INSTRB( FormData, bnCRLF & bnCRLF ) + 4 
DataEnd = INSTRB( DataStart + 1, FormData, divider ) - DataStart
Response.ContentType = "image/gif"
Response.BinaryWrite MIDB( FormData, DataStart, DataEnd )
%>



下面一段读数据库中的图像字段并显示在网页上的代码,显示的却全是乱码,请高手诊断。    


--------------------------------------------------------------------------------

 【我是菜鸟我怕谁】 于 2000-05-31 09:45:20 加贴在 Joy ASP ↑  

<% dim cn
   Response.ContentType="image/*"

   set cn=server.CreateObject("adodb.connection")
   cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\db1.mdb;Persist Security Info=False" 
   dim rs 
   dim l
   l=8192
   set rs=server.CreateObject("adodb.recordset")
   rs.Open "select * from T2",cn,1,1,1
   rs.MoveFirst 
   dim p
   do while true
     p=rs.Fields("image").GetChunk(l) 
     Response.BinaryWrite p
     if lenb(p)<l then 
       exit do
     end if       
   loop
    set rs=nothing
    set cn=nothing
    %>



参考下列程序    


--------------------------------------------------------------------------------

 【梦】 于 2000-05-31 10:07:46 加贴在 Joy ASP ↑  

<HTML>
<HEAD><TITLE> File Upload </TITLE></HEAD>
<BODY>

<FORM ENCTYPE="multipart/form-data"
ACTION="uploadresult.asp" METHOD=POST>

Please choose a picture to uploads:
<BR><INPUT NAME="picture" TYPE=FILE ACCEPT="image/gif">
<BR><INPUT TYPE=SUBMIT VALUE="Submit Me!">
</FORM>

</BODY>
</HTML>

uploadresult.asp:
<%
FormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )
bnCRLF = chrB( 13 ) & chrB( 10 )
Divider = LEFTB( FormData,  INSTRB( FormData, bnCRLF ) - 1 )
DataStart = INSTRB( FormData, bnCRLF & bnCRLF ) + 4 
DataEnd = INSTRB( DataStart + 1, FormData, divider ) - DataStart
Response.ContentType = "image/gif"
Response.BinaryWrite MIDB( FormData, DataStart, DataEnd )
%>


上载图像的form中可以有其它类型的input吗?我上载图像的form中加上(enctype="multipart/form-data")
后其他的input中的内容提交后就不正确了    


--------------------------------------------------------------------------------





再求教asp取图像实际尺寸???那位高手接招??    


--------------------------------------------------------------------------------

 【recowen】 于 2000-04-26 15:28:00 加贴在 Joy ASP ↑   

取GIF正确
取bmp or jpg就不对了??
附文件:
<% 
Dim HW 
Function AscAt(s, n) 
       AscAt = Asc(Mid(s, n, 1))
       
End Function 

Function HexAt(s, n) 
       HexAt = Hex(AscAt(s, n))
End Function 


Function isJPG(fichero) 
       If inStr(uCase(fichero), ".JPG") <> 0 Then 
       isJPG = true 
       Else 
       isJPG = false 
       End If 
End Function 


Function isPNG(fichero) 
       If inStr(uCase(fichero), ".PNG") <> 0 Then 
       isPNG = true 
       Else 
       isPNG = false 
       End If 
End Function 


Function isGIF(fichero) 
       If inStr(uCase(fichero), ".GIF") <> 0 Then 
       isGIF = true 
       Else 
       isGIF = false 
       End If 
End Function 


Function isBMP(fichero) 
       If inStr(uCase(fichero), ".BMP") <> 0 Then 
       isBMP = true 
       Else 
       isBMP = false 
       End If 
End Function 


Function isWMF(fichero) 
       If inStr(uCase(fichero), ".WMF") <> 0 Then 
       isWMF = true 
       Else 
       isWMF = false 
       End If 
End Function 


Function isWebImg(f) 
       If isGIF(f) Or isJPG(f) Or isPNG(f) Or isBMP(f) Or isWMF(f) Then 
       isWebImg = true 
       Else 
       isWebImg = true 
       End If 
End Function 


Function ReadImg(fichero) 
       If isGIF(fichero) Then 
       ReadImg = ReadGIF(fichero)
       response.write "gif" 
       Else 
       If isJPG(fichero) Then 
       ReadImg = ReadJPG(fichero)
       response.write "jpg"  
       Else 
       If isPNG(fichero) Then 
       ReadImg = ReadPNG(fichero) 
       Else 
       If isBMP(fichero) Then 
       ReadImg = ReadPNG(fichero) 
       Else 
       If isWMF(fichero) Then 
       ReadImg = ReadWMF(fichero) 
       Else 
       ReadImg = Array(0,0) 
       End If 
       End If 
       End If 
       End If 
       End If 
End Function 


Function ReadJPG(fichero) 
    Dim fso, ts, s, HW, nbytes 
      HW = Array("","") 
     Set fso = CreateObject("Scripting.FileSystemObject") 
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
       s = Right(ts.Read(167), 4) 
       HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
       HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2))
       ts.Close 
    ReadJPG = HW   
End Function 


Function ReadPNG(fichero) 
    Dim fso, ts, s, HW, nbytes 
       HW = Array("","") 
       Set fso = CreateObject("Scripting.FileSystemObject") 
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
       s = Right(ts.Read(24), 8) 
       HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4)) 
       HW(1) = HexToDec(HexAt(s,7) & HexAt(s,8)) 
       ts.Close 
    ReadPNG = HW 
End Function 


Function ReadGIF(fichero) 
    Dim fso, ts, s, HW, nbytes 
       HW = Array("","") 
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
       s = Right(ts.Read(10), 4) 
       HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1)) 
       Response.Write HexAt(s,2) & HexAt(s,1) & "hh" 
       HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3)) 
       Response.Write HexAt(s,4) & HexAt(s,3) & "ww"
       ts.Close 
    ReadGIF = HW 
End Function 


Function ReadWMF(fichero) 
    Dim fso, ts, s, HW, nbytes 
       HW = Array("","") 
       Set fso = CreateObject("Scripting.FileSystemObject") 
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
       s = Right(ts.Read(14), 4) 
       HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1)) 
       HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3)) 
       ts.Close 
    ReadWMF = HW 
End Function 


Function ReadBMP(fichero) 
    Dim fso, ts, s, HW, nbytes 
       HW = Array("","") 
       Set fso = CreateObject("Scripting.FileSystemObject") 
       Set ts = fso.OpenTextFile(Server.MapPath("/" & fichero), 1) 
       HW(0) = HexToDec(HexAt(s,4) & HexAt(s,3)) 
       HW(1) = HexToDec(HexAt(s,8) & HexAt(s,7)) 
       ts.Close 
    ReadBMP = HW 
End Function 


Function isDigit(c) 
       If inStr("0123456789", c) <> 0 Then 
       isDigit = true 
       Else 
       isDigit = false 
       End If 
End Function 


Function isHex(c) 
       If inStr("0123456789ABCDEFabcdef", c) <> 0 Then 
       isHex = true 
       Else 
       ishex = false 
       End If 
End Function 


Function HexToDec(cadhex) 
       Dim n, i, ch, decimal 
       decimal = 0 
       n = Len(cadhex) 
       For i=1 To n 
       ch = Mid(cadhex, i, 1) 
       If isHex(ch) Then 
       decimal = decimal * 16 
       If isDigit(ch) Then 
       decimal = decimal + ch 
       Else 
       decimal = decimal + Asc(uCase(ch)) - Asc("A") + 10
       End If 
       Else 
       HexToDec = -1 
       End If 
       Next 
       HexToDec = decimal 
End Function 
%>
<html><head>
<TITLE>dbtable.asp</TITLE>
</head>
<body bgcolor="#FFFFFF">
<p>
<%
   graphic="test1/images/city02.gif"
   HW = ReadImg(graphic)
   Response.Write graphic & " Dimensions: " & HW(0) & "x" & HW(1) & "<br>"
   response.write "<img src=""/" & graphic & """" 
   response.write height=""" & HW(0) & """
   response.write width=""" & HW(0) & "">"
%>
</p>
</body></html> 



回复:各位老大帮忙解解惑吧:将图像存在ACCESS数据库里是否有以下缺点:<内详,务请帮忙解答>    


--------------------------------------------------------------------------------

 【even】 于 2000-04-25 08:46:11 加贴在 Joy ASP ↑  

1。数据库庞大有两种,一是数据量大,二是数据本身大,图象属于数据本身大,与数据库速度关系影响不大(个人观点),数据量庞大对数据库性能影响是比较大的。
2。HTML一般是顺序读取的,但遇到图象等内容时的确会滞后显示,如果数据库不是特别慢的话,这种区别(数据库与非数据库)不太明显。
3。图象存储在数据库中易于管理,如查询,删除,清空等,仅存储文件名的方式易于实现,速度快,但文件量一旦增大,势必带来麻烦。





78个字节的ole头一般无法使用,我是这样解决的
先将数据库中blob字段中的所有数据读出来写到一个新的文件中,然后用
二进制文本工具将原来的图形文件同新生成的文件比较,然后就知道有
几个字节的文件头了!!!

你可以使用我的lyfimage组件,就是这样做的!http://aspfans.yeah.net 中有lyfimage组件可以用


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -