哪位提供最简单的图片存入库中的代码

99028 2001-07-12 04:29:32
急用的,拜托各位了 :)
...全文
63 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
99028 2001-07-12
多谢各位,谢谢!!
回复
dotnba 2001-07-12
<% @Language=VBScript %>
<% response.buffer=true %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
dim formsize,formdata,vbcrlf
dim datastart,dataend,mydata,datasize
dim connGraph

formsize = request.totalbytes

formdata = request.binaryread(formsize)

vbcrlf = chrB(13) & chrB(10)

'首先从上面FORM传来的数据中找到到第一个回车换行符的位置为止的字符串,并作为分隔串
divider = LeftB(formdata , clng(instrb(formdata,vbcrlf)) - 1)

'找到真正数据的开始位置,在连续两个回车换行符号的后面加4是因为两个回车换行是占4个字节
datastart = InStrB(formdata , vbcrlf & vbcrlf) + 4

'找到真正数据的结束位置,减掉一个开始位置,其实DATAEND就成了数据长度
dataend = instrb(datastart + 1 , formdata , divider)

datasize = dataend - datastart

mydata = MidB(formdata , datastart ,datasize)

set conn = server.CreateObject("ADODB.connection")

set rs = server.CreateObject("ADODB.recordset")

Conn_String = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath ("images.mdb")

Conn.Open (conn_string)

rs.Open "SELECT * FROM [images] where id is null",conn,1,3

rs.addnew

rs("img").appendchunk mydata

rs("size") = datasize

rs.update

rs.Close
conn.Close

Response.Write ("已经成功上传")
%>
<br>

查看图片已经上传图片。
<form action = "show.asp" method="post">
<input type="text" size=2 name = "id">
<input type=submit name = "submit" value = "查看">
</form>
</BODY>
</HTML>
<% @Language=VBScript %>
<% Response.ContentType = "image/*" %>
<% 'Response.ContentType = "text/*" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<%

set conn = server.CreateObject("ADODB.connection")
set rs = server.CreateObject("ADODB.recordset")

Conn_String = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & server.MapPath ("images.mdb")
Conn.Open (conn_string)

strsql = "select max(id) from images"

rs.open strsql,conn,1,1

if not rs.EOF then
maxid = rs(0)
end if

rs.Close

strsql = "select img from images where id = " & maxid

rs.open strsql,conn,1,1

if not rs.EOF then
Response.BinaryWrite rs("img").getChunk(rs("size"))
end if

rs.close
conn.close

%>

</BODY>
</HTML>
回复
freezwy 2001-07-12
你先测试一下,如果没有问题,弄几分。


-------------------------------------------------
ASP混子来混分,得分能得免费杂志,哈哈,下次改签名
-------------------------------------------------
回复
孟子E章 2001-07-12
http://www.51soft.com/code/code.asp?search=32
回复
孟子E章 2001-07-12
asp3.0:
field对象的方法:appendchunk-附加数据给大型的或者2进制的FIELD对象
回复
99028 2001-07-12
多谢,多谢,有劳你了,好运 :)
回复
freezwy 2001-07-12
给你个简单的。从网上拉的一个,很好用。
三个文件。
-----数据结构---access的
user 文本
imagedata ole对象
-----------------------default.asp----------------------
<html>
<head>
<title>上传图标</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
table { font-size: 9pt}
select { font-size: 9pt}
input { font-size: 9pt; background-color: #CCCCFF; font-weight: bold; color: #FF6633; border-style: groove}
.smallbox { font-size: 1pt}
a:link { font-size: 9pt; text-decoration: none; }
a:hover { font-size: 9pt;}
body { font-size: 9pt}
-->
</style>
</head>

<body bgcolor="#FFFFFF">
<table width="95%" border="0" align="center" cellpadding="5">
<tr align="center" valign="middle">
<td> <b> </b>
<form method="post" action="savelogo.asp" name="reg" enctype="multipart/form-data">
文件名:
<input type="file" name="file" size="32">
<br>
用户名:
<input type="text" name="id" value="test">
(如果已经存在用户,则覆盖)<br>
<input type="submit" name="Submit" value="开始上传">
<input type="reset" name="reset" value="重新选择">
<br>
</form>
</td>
</tr>
</table>
<script language=vbscript>
function reg_Onsubmit()
if document.reg.id.value="" then
msgbox "用户名必须填写!"
reg_onsubmit=false
exit function
else
document.reg.action="save.asp?id="&document.reg.id.value
end if
end function
</script>
</body>
</html>
------------------------------save.asp-----------------
<%
' Allrights Qbtrade.com
' Maozai
dim conn
dim connstr
dim rs
dim sql

on error resume next
call conn_init()
id=request("id")

FormSize = Request.TotalBytes
FormData = Request.BinaryRead(FormSize)
Image=ImageUp (FormSize,Formdata)

set rs=server.CreateObject("adodb.recordset")
sql="SELECT * FROM imgdata WHERE user ='" &id &"'"
rs.Open sql,conn,1,3
if rs.recordcount = 0 then
rs.close
sql="SELECT * FROM imgdata"
rs.Open sql,conn,1,3
rs.AddNew
rs("user") = id
rs("imagedata") = NULL
rs("imagedata").appendchunk Image
else
rs("imagedata") = NULL
rs("imagedata").appendchunk Image
end if

rs.Update
rs.Close
set rs=nothing
endconnection


%>
<style type="text/css">
<!--
table { font-size: 9pt}
select { font-size: 9pt}
input { font-size: 9pt; background-color: #CCCCFF; font-weight: bold; color: #FF6633; border-style: groove}
.smallbox { font-size: 1pt}
a:link { font-size: 9pt; text-decoration: none; }
a:hover { font-size: 9pt;}
body { font-size: 9pt}
-->
</style>
<title>完成</title>
<body bgcolor="#FFFFFF" text="#000000">
<table width="95%" border="0" align="center" cellpadding="5" height="167">
<tr align="center" valign="middle">
<td height="128">
<p>恭喜,<%=id%>,你已经上传了你的图标,加入了QBTrade宣传的行列!</p>
<p>以下是你刚才上传的图标,如果你不满意,可以返回重新修改一次。</p>
<p><img src="show.asp?id=<%=id%>"></p>
</td>
</tr>
</table>
<p align="center"></p>
<%
function ImageUp(formsize,formdata)
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
imageup=midb(formdata,datastart,dataend)
end function

'-------------------------
sub conn_init()
connstr="DBQ="+server.mappath("image.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
conn.open connstr
if err then
'err.clear
set conn=nothing
response.write "数据库连接出错!!!<br>" + err.description
err.clear
Response.End
end if
end if
end sub

sub endConnection()
conn.close
set conn=nothing
end sub

%>
----------------show.asp------------------
<%

dim conn
dim connstr
dim rs
dim sql
dim id
id = request("id")

on error resume next
call conn_init()

set rs=server.CreateObject("adodb.recordset")
sql="SELECT * FROM imgdata WHERE user = '" & id & "'"
rs.Open sql,conn,1,1
if rs.recordcount = 0 then
rs.close
rs.open "SELECT * FROM imgdata WHERE user = 'not_available'",conn,1,1
end if
response.contenttype="x-mixed-replace"
Response.BinaryWrite rs("imagedata")
rs.Close

endconnection

function ImageUp(formsize,formdata)
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
imageup=midb(formdata,datastart,dataend)
end function

'-------------------------
sub conn_init()
connstr="DBQ="+server.mappath("image.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
conn.open connstr
if err then
'err.clear
set conn=nothing
response.write "数据库连接出错!!!<br>" + err.description
err.clear
Response.End
end if
end if
end sub

sub endConnection()
conn.close
set conn=nothing
end sub

%>

回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2001-07-12 04:29
社区公告
暂无公告