请问各位怎样向数据库同时插入图片与文本啊?
我想 同时往数据库里写入二进制数据与文本请问该怎么做?
upload.htm
插入 文本与二进制数据 的页面 上传图片与插入文本字段
<form name="mainForm" enctype="multipart/form-data"
action="process.asp?action=1" method=post>
<table width="530" height="30" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div align="center">精品活动</div></td>
</tr>
</table>
<table width="530" height="250" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="104"><div align="center" class="style1"></div> <div align="center" class="style1">图片</div></td>
<td width="15" rowspan="2"> </td>
<td width="410" height="30"><input type=file name=mefile></td>
</tr>
<tr>
<td><div align="center" class="style1">标题</div></td>
<td width="410" height="30"><input name="title" type="text" id="title"></td>
</tr>
<tr>
<td height="20" colspan="3"><div align="center">
<input type=submit name=ok value="提 交">
</div></td>
</tr>
</table>
</form>
process.asp 向数据库插入一条记录
<!--#include file="conn.asp" -->
<%
response.buffer=true
formsize=request.totalbytes
formdata=request.binaryread(formsize)
bncrlf=chrB(13) & chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
mydata=midb(formdata,datastart,dataend)
set rec=server.createobject("ADODB.recordset")
sql="SELECT * FROM [images] where id is null"
rec.Open sql,conn,1,3
rec.addnew
rec("img").appendchunk mydata
rec.update
rec.close
set rec=nothing
set connGraph=nothing
response.redirect "look.asp"
%>
images 表
id img(OLE对象) title(文本)
请问那位专家能够帮我解决这个问题 谢谢!
问题点数:40、回复次数:4Top
1 楼znjgress(四空和尚)回复于 2006-02-07 13:44:43 得分 40
<!--#include file="conn_pic.asp"-->
<!--#include file="fupload.inc"-->
<%
Set Fields = GetUpload()
For Each Field In Fields.Items
if Field.name = "title" then title = BinaryToString(Field.value)
if Field.name = "content" then content = BinaryToString(Field.value)
if Field.name = "from" then from = BinaryToString(Field.value)
if Field.name = "file1" then
filename = field.FileName
fileContentType = field.ContentType
filevalue = field.value
end if
next
sql = "select * from fileTest"
rs.Open sql,conn,1,3
rs.addnew
if filename <> "" then
rs("filename") = filename
rs("fileType") = fileContentType
rs("fileContent").appendchunk filevalue
end if
rs.Update
rs.close
set rs = nothing
%>
以二进制写入sqlTop
2 楼znjgress(四空和尚)回复于 2006-02-07 13:45:09 得分 0
<%
response.Expires=0
response.Buffer=true
response.Clear
dim picId
picId = int(request("c_login_id"))
response.Write(picId)
strsql="select c_photo_pic from t_photo where c_login_id = 5 " '& picId
rs.open strsql,conn,3,1
'response.BinaryWrite(rs("c_photo_pic"))
'response.End()
if rs.recordcount <> 0 then
response.ContentType="image/*"
response.BinaryWrite(rs("c_photo_pic"))
end if
%>
读出Top
3 楼ervinlj(阳光使者)回复于 2006-02-07 14:30:29 得分 0
谢谢楼上的这位高人,但我对你的存入字段内容还是有点不明白.
<!--#include file="conn_pic.asp"-->
<!--#include file="fupload.inc"-->
第一个可能是数据库连接文件, 那第二个include进来的是什么东西呀?
还有以下这段代码:
Set Fields = GetUpload()
For Each Field In Fields.Items
if Field.name = "title" then title = BinaryToString(Field.value)
if Field.name = "content" then content = BinaryToString(Field.value)
if Field.name = "from" then from = BinaryToString(Field.value)
if Field.name = "file1" then
filename = field.FileName
fileContentType = field.ContentType
filevalue = field.value
end if
next
BinaryToString(Field.value)是什么意思?
if Field.name = "file1" then
filename = field.FileName
fileContentType = field.ContentType
filevalue = field.value
end if
这个判断又是用来干什么的?
Set Fields = GetUpload() 能否提供GetUpload函数的源代码?
另外请说明这个函数所返回的值Fields是什么东西???
小弟我初学Asp,有些东西还不是很明白,请指教.
Top
4 楼ervinlj(阳光使者)回复于 2006-02-07 15:54:37 得分 0
up一下Top




