📄 图像问题.txt
字号:
请问:有谁按照精华区“用纯ASP将图片存入数据库”一文成功操作过,我已经试了N回了,但始终不能PASS,请问谁那里有关于图片上载存入数据库的文章或代码,请介绍给我,多谢了! <无内容> - 【走着瞧】 2000-07-12 17:35:29 [ID:345931 点击:4] (0 Bytes) (1)
苦心源码,欢迎下载 - 【ASP fans】 2000-07-12 17:51:06 [ID:345984 点击:46] (7701 Bytes) (1)
补充 - 【ASP fans】 2000-07-12 17:53:35 [ID:345993 点击:20] (49 Bytes) (1)
苦心源码,欢迎下载
--------------------------------------------------------------------------------
【ASP fans】 于 2000-07-12 17:51:06 加贴在 Joy ASP ↑
SavePic.asp
<%
'---------------------------------------RETURN THE IMAGE FORMAT--------------------
function checkImageFormat(checkdata)
'--return: A,B,C (A is image format; B is height pixels; C is width pixels; D is color depth)
flag=0 '''''''0 is not jpg/gif/png image; 1 is jpg/gif/png
'-------------------------------------------------------check jpg----------------
if flag=0 then
tempstr=Leftb(checkdata,10)
tstr=chrb(255)&chrb(216)&chrb(255)&chrb(224)&chrb(0)&chrb(16)&chrb(74)&chrb(70)&chrb(73)&chrb(70)
if strcomp(tempstr,tstr,0)=0 then
msgstr01="jpg"
lngSize = len(checkdata)
flgFound = 0
strTarget = chrb(255) & chrb(216) & chrb(255)
flgFound = instrb(checkdata, strTarget)
lngPos = flgFound + 2
ExitLoop = false
do while ExitLoop = False and lngPos < lngSize
do while ascb(midb(checkdata, lngPos, 1)) = 255 and lngPos < lngSize
lngPos = lngPos + 1
loop
if ascb(midb(checkdata, lngPos, 1)) < 192 or ascb(midb(checkdata, lngPos, 1)) > 195 then
lngMarkerSize = lngConvert2(midb(checkdata, lngPos + 1, 2))
lngPos = lngPos + lngMarkerSize + 1
else
ExitLoop = True
end if
loop
i_Height = lngConvert2(midb(checkdata, lngPos +4, 2))
i_Width = lngConvert2(midb(checkdata, lngPos +6, 2))
i_Depth = 2 ^ (ascb(midb(checkdata, lngPos + 8, 1)) * 8)
msgstr02=","& i_height & "," & i_width
flag=2
else
flag=0
end if
end if
'--------------------------------------------------check gif--------------------------------
if flag=0 then
tempstr=Leftb(checkdata,6)
tstr=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(57)&chrb(97)
tstr2=chrb(71)&chrb(73)&chrb(70)&chrb(56)&chrb(55)&chrb(97)
if strcomp(tempstr,tstr,0)=0 or strcomp(tempstr,tstr2)=0 then
msgstr03="gif"
i_width=lngConvert(midb(checkdata,7,2))
i_height=lngConvert(midb(checkdata,9,2))
i_Depth = 2 ^ ((ascb(midb(checkdata, 11, 1)) and 7) + 1)
msgstr04=","& i_height & ","& i_width
flag=2
else
flag=0
end if
end if
'---------------------------------------------------check png------------------------------
if flag=0 then
tempstr=Leftb(checkdata,4)
tstr=chrb(137)&chrb(80)&chrb(78)&chrb(71)
if strcomp(tempstr,tstr,0)=0 then
msgstr05="png"
i_Width = lngConvert2(midb(checkdata, 19, 2))
i_Height = lngConvert2(midb(checkdata, 23, 2))
i_Depth = lngConvert(midb(checkdata, 25, 2))
select case ascb(right(i_Depth,1))
case 0
i_Depth = 2 ^ (asc(left(i_Depth, 1)))
gfxSpex = True
case 2
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 3)
gfxSpex = True
case 3
i_Depth = 2 ^ (asc(left(i_Depth, 1))) '8
gfxSpex = True
case 4
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 2)
gfxSpex = True
case 6
i_Depth = 2 ^ (asc(left(i_Depth, 1)) * 4)
gfxSpex = True
case else
i_Depth = -1
end select
msgstr06=","& i_height & ","& i_width
flag=2
else
flag=0
end if
end if
if flag=0 then
msgstr07="no image"
end if
msgstr=msgstr01 & msgstr02 & msgstr03 & msgstr04 & msgstr05 & msgstr06 & msgstr07
checkImageFormat=msgstr
end function
function lngConvert2(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
lngConvert2 = clng(ascb(str2) + ((ascb(str1) * 256)))
end function
function lngConvert(strTemp)
str1=leftb(strTemp,1)
str2=rightb(strTemp,1)
len1=ascb(str1)
len2=ascb(str2)
lngConvert = clng(ascb(str1) + ascb(str2) * 256)
end function
'------------------------Copyright by qinls------------------
%>
<%
Response.buffer=true '将服务端传送给缓冲区
filesize=Request.totalbytes '客户端响应数据字节的大小
filedata=Request.binaryread(filesize) '得到数据量要小于或等于totalbytes
'*******得到有效的图片的信息*********
bncrlf=chrB(13) & chrB(10)
divider=leftB(filedata,clng(instrB(filedata,bncrlf))-1)
datastart=instrb(filedata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,filedata,divider)-datastart '(搜索的起点,字符串1,字符串2)
mydata=midb(filedata,datastart,dataend)
arrayMessage=split(checkImageFormat(mydata),",")
'*********************************
%>
<% if arrayMessage(1)>150 OR arrayMessage(2)>100 then %>
<script language="javascript">
alert("您所选择的图片的尺寸不符合要求!应在 高*宽 150*100 之间")
window.location="SP.htm"
</script>
<% Else
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.createobject("ADODB.Recordset")
Rs.Open "SELECT * FROM T1 where ID is Null",Cn,1,3
Rs.Addnew
Rs.Fields("IMG").appendchunk mydata
Rs.Update
Rs.Close
Set Rs=nothing
Set Cn=nothing
End if
%>
<script language="Javascript">
window.location="SP.htm"
</script>
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SearchPic.asp
<script language="javascript">
</script>
<%
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.Createobject("ADODB.Recordset")
Sql="SELECT * from T1"
Rs.open Sql,Cn,2,3
Response.Write "<table width=""100%"" cellspacing=""0"" cellpadding=""0"" border=""2"" bordercolor=""#CCCCCC"" align=""center"">"
Do While NOT Rs.EOF
Response.Write "<tr>"
Response.Write "<td>"
Response.Write trim(Rs.Fields("ID"))
Response.Write "</td>"
Numberimg=Rs.Fields("ID")
Response.Write "<td>"
Response.Write "<IMG SRC=""ShowPic.asp?ID=" & Numberimg & """>"
Response.Write "</td>"
Rs.MoveNext
Response.Write "</tr>"
Loop
Response.Write "</table>"%>
<% Response.Write "<P></P>" %>
<input type="button" value="继续上传图片" onclick="window.location='SP.htm'">
<%Rs.Close
Cn.Close
%>
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SeeBig.asp
<HTML>
<BODY >
<input type="image" name="img1" SRC= <%=Request("FFF") %> >
</BODY>
</HTML>
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
ShowPic.asp
<%
Set Cn=server.CreateObject("ADODB.connection")
Cn.ConnectionString="Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("pic.mdb")
Cn.Open
Set Rs=Server.Createobject("ADODB.recordset")
Sql="SELECT IMG from T1 WHERE ID=" & Request("ID")
Rs.open Sql,Cn,1,1
Response.ContentType = "image/*"
Response.BinaryWrite Rs("IMG").getChunk(7500000)
Rs.Close
Set Rs=nothing
Set Cn=nothing
%>
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
SP.htm
<html>
<head>
<script language="JavaScript">
function See(hh,ff) {
hh.src=ff.value
}
function SeeBig(filepath){
window.open("SeeBig.asp?FFF="+filepath,"","");
}
</Script>
</head>
<body>
<form name="f1" enctype="multipart/form-data" action="SavePic.asp" method=post>
<input type=file name="file1">
<input type="button" name="b1" value="预览" onClick="See(this.form.picview,this.form.file1)" >
<input type=submit name="upfile" value="上传">
<br>
<img src="image/view.JPG" name="picview" width="100" height="120" Border="0" alt="单击放大" onClick="SeeBig(file1.value)">
</form>
<form name="f2" action="SearchPic.asp" method="post">
<input type="submit" name="s2" value="查看所有上传图片">
</form>
</body>
</html>
数据库是 pic.mdb
字段 ID 自动加一 PCI 二进制
appendchunk
--------------------------------------------------------------------------------
【水蝴蝶】 于 2000-06-08 11:13:17 加贴在 Joy ASP ↑
contentType = UploadRequest.Item("upfile").Item("ContentType")
filepathname = UploadRequest.Item("upfile").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
picture = UploadRequest.Item("upfile").Item("Value")
.......
rs("img").appendchunk picture
rs.update
回复:无组件方法(支持中文)
--------------------------------------------------------------------------------
【水蝴蝶】 于 2000-06-08 11:06:59 加贴在 Joy ASP ↑
图片与文字不能同时提交主要是由于BinaryRead不能与request.form同时用,只好
另想办法了如下:
dim upfile,topic,......
.......
byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin
Set Fields = GetUpload(RequestBin)
upfile=Fields("upfile").Value
topic=Fields("topic").Value
..........
<!--#include file="upload.asp"-->
//////////////////////////////////////
附upload.asp
<%
Sub BuildUploadRequest(RequestBin)
'Get the boundary
PosBeg = 1
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
boundaryPos = InstrB(1,RequestBin,boundary)
'Get all data inside the boundaries
Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
'Members variable of objects are put in a dictionary object
Dim UploadControl
Set UploadControl = CreateObject("Scripting.Dictionary")
'Get an object name
Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
Pos = InstrB(Pos,RequestBin,getByteString("name="))
PosBeg = Pos+6
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
Name = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
PosFile = InstrB(BoundaryPos,RequestBin,getByteString("filename="))
PosBound = InstrB(PosEnd,RequestBin,boundary)
'Test if object is of file type
If PosFile<>0 AND (PosFile<PosBound) Then
'Get Filename, content-type and content of file
PosBeg = PosFile + 10
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(34)))
FileName = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
'Add filename to dictionary object
UploadControl.Add "FileName", FileName
Pos = InstrB(PosEnd,RequestBin,getByteString("Content-Type:"))
PosBeg = Pos+14
PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
'Add content-type to dictionary object
ContentType = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
UploadControl.Add "ContentType",ContentType
'Get content of object
PosBeg = PosEnd+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
Else
'Get content of object
Pos = InstrB(Pos,RequestBin,getByteString(chr(13)))
PosBeg = Pos+4
PosEnd = InstrB(PosBeg,RequestBin,boundary)-2
Value = getString(MidB(RequestBin,PosBeg,PosEnd-PosBeg))
End If
'Add content to dictionary object
UploadControl.Add "Value" , Value
'Add dictionary object to main dictionary
UploadRequest.Add name, UploadControl
'Loop to next object
BoundaryPos=InstrB(BoundaryPos+LenB(boundary),RequestBin,boundary)
Loop
End Sub
'String to byte string conversion
Function getByteString(StringStr)
For i = 1 to Len(StringStr)
char = Mid(StringStr,i,1)
getByteString = getByteString & chrB(AscB(char))
Next
End Function
'Byte string to string conversion
Function getString(StringBin)
getString =""
For intCount = 1 to LenB(StringBin)
getString = getString & chr(AscB(MidB(StringBin,intCount,1)))
Next
End Function
%>
上传图片到ORACLE数据库中,是不是跟上传到SQL中一样?怎么我上传后看不到图片?
--------------------------------------------------------------------------------
【flywing】 于 2000-06-02 13:40:59 加贴在 Joy ASP ↑
我照这里精华区的方法,把图片上传到SQL中没问题,可是上传到ORACLE中后,
再读出来就看不到图片,我也不知是否上传成功。
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -