电信主站 网通分站
购买流程 付款方式 常见问题 在线提问 续租服务 购物车
用户名: 密 码: 忘记密码?
首 页
域名注册
虚拟主机
双线主机
服务器租用
VPS主机
企业邮局
代理专区
客服中心
虚拟主机行业资讯 虚拟主机评测对比 互联网最新动态 技术学院 站长资讯 在线教程 网站运营
搜索优化 服务器 网络编程 图形图象 站长之家 网页制作 操作系统
冲浪宝典 软件教学 视频通信 办公软件 邮件系统 网络安全 认证考试
您当前位置:西部数码->资讯中心-> 在线教程-> 数据库
无组件上传图片到数据库中,最完整解决方案
作者:网友供稿 点击:9
  西部数码-全国虚拟主机10强!20余项虚拟主机管理功能,全国领先!第6代双线路虚拟主机,南北访问畅通无阻!虚拟主机可在线rar解压,自动数据恢复设置虚拟目录等.虚拟主机免费赠送访问统计,企业邮局.Cn域名注册10元/年,自助建站480元起,免费试用7天,满意再付款!P4主机租用799元/月.月付免压金!
文章页数:[1] 
::::::: 此程序属扬子原创 ::::::::::::::::::
:::::: 在sql2000,2000s中测试通过::::::::
:::::::联系我:qq:21112856,email:yangzinet@hotmail.com:::::::::
::::::: http://www.tingfo.net ::::::


up.htm

<!--#include file="inc/domin.asp"-->
<!--#include file="conn.asp"-->
<html>
<head>
<title><% =webname %></title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="main.css" type="text/css">
<style type="text/css">
<!--
.tx1 { height: 20px; width: 30px; font-size: 9pt; border: 1px solid; border-color: black black

#000000; color: #0000ff}
-->
</style>

<script language="javascript">
<!--
var bgc_on=new array("#74d738","#ff9c17","#3278ab","#486177","#078c00","#007eca")
var bgc_off=new array("#4cad12","ffb859","5f9fd0","577590","08a700","009fff")

function turnon(obj1,id){
obj1.style.background=bgc_on[id];
}
function turnoff(obj1,id){
obj1.style.background=bgc_off[id];
}

//-->
</script>
<script language=javascript>
function check_input()
{
if (frm.pic.value=="")
{ alert("请选择要上传的图片");
return false;
}
if (frm.type.value=="")
{ alert("请选择图片类型");
return false;
}
if (frm.thetext.value=="")
{ alert("请输入照片说明");
return false;
}
return true;
}
</script>
</head>

<body bgcolor="#555555" text="#000000" leftmargin="0" topmargin="0">
<table width=755 cellpadding=0 cellspacing=0 border=0 bgcolor=#ffffff align="center">
<tr>
<td height=100><img src="img/top.gif" align="top">
</table>

<!--#include file="inc/mulu.asp"-->


<table width=755 cellpadding=0 cellspacing=0 border=0 bgcolor=#ffffff align="center" bordercolor=#000000>
<tr>
<td height=400 width=180 bgcolor=#d1e9d5 style="border-right: 1px #0e801e solid">
<table width=100% height=100% cellpadding=0 cellspacing=0 border=0 align="center" bordercolor=#000000>
<tr><td height=30 align="center" class=l15><font color=#e96d08>欢迎你:<% =username %> 管理中心</font>
<tr><td height=23 align="center" class=l15 bgcolor=#4cad12 style="border-top:0px #0e801e solid; border-bottom:1px #0e801e solid;"><font color=#c2f009 class=yinying>管 理 中 心</font>
<tr><td height=20 class=l13>
<!--#include file="inc/centermulu.asp"-->
<tr><td height=5>
<tr><td>
</table>
<td>
<%
set rs=server.createobject("adodb.recordset")
sql="select * from photo where author="&username&""
rs.open sql,conn,1,1
%>
<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>
<tr><td height=3>
<tr><td height=3 bgcolor=#ffffff background=img/bj3.gif>
<tr><td height=20 valign="bottom" bgcolor=#eeeeee> 现在位置: 98243班 - 管理中心 - 添加新闻
<tr><td height=3 bgcolor=#eeeeee style="border-bottom: 1px #cccccc solid"><p style="font-size:1pt">
<tr><td height=20 valign="bottom"> <font color=green><% =username %>:你一共上传了 <font color=red><% =rs.recordcount %></font> 张照片</font> <a href="adminphoto.asp"><font color=red><u>管理以前上传的照片</u></font></a>
<tr><td bgcolor=#ffffff valign=top>
<table cellpadding=0 cellspacing=0 border=0 width=95% height=100% align="center">
<form action=addphoto.asp method=post name=frm onsubmit="return check_input()" enctype="multipart/form-data">
<tr><td height=20 colspan=2>
<tr><td height=25 width=15% align="right" class=l13>选择照片: <td> <input name="pic" type="file" class="tx1" style="width:300"> <font color=red>拒绝色情、写真图等</font>

<tr><td height=25 width=20% align="right" class=l13>照片分类: <td> <select name="type">
<option selected value="">选择类型</option>
<option value="班级合影">班级合影</option>
<option value="个人照片">个人照片</option>
<option value="恩师照片">恩师照片</option>
<option value="情人照片">情人照片</option>
<option value="友人照片">友人照片</option>
<option value="其他照片">其他照片</option>
</select>

<tr><td height=25 width=20% align="right" class=l13>照片说明: <td> <textarea name="thetext" cols="46" rows="7" style="border:1px double rgb(88,88,88);font:9pt">
</textarea> <font color=red>最多20个字符</font>
<tr><td height=5 colspan=2>
<tr><td height=25 colspan=2 align="center">
<input type="submit" name="submit" value=" 提 交 " style="border:1px double rgb(88,88,88);font:9pt">
   <input type="reset" name="reset" value=" 重 写 " style="border:1px double rgb(88,88,88);font:9pt">
<tr><td colspan=2>
</tr></form>
</table>
</table>

</table>
<!--#include file="inc/footer.asp"-->
</body>
</html>


fupload.inc

<script runat=server language=vbscript>
限制上传图片大小
dim uploadsizelimit

********************************** 得到上传数据 **********************************
function getupload()
dim result
set result = nothing
if request.servervariables("request_method") = "post" then request method must be "post"
dim ct, posb, boundary, length, pose
ct = request.servervariables("http_content_type") reads content-type header
if lcase(left(ct, 19)) = "multipart/form-data" then content-type header must be "multipart/form-data"
this is upload request.
get the boundary and length from content-type header
posb = instr(lcase(ct), "boundary=") finds boundary
if posb > 0 then boundary = mid(ct, posb + 9) separetes boundary
length = clng(request.servervariables("http_content_length")) get content-length header
if "" & uploadsizelimit<>"" then
uploadsizelimit = clng(uploadsizelimit)
if length > uploadsizelimit then
on error resume next clears the input buffer
response.addheader "connection", "close"
on error goto 0
request.binaryread(length)
err.raise 2, "getupload", "upload size " & formatnumber(length,0) & "b exceeds limit of " & formatnumber(uploadsizelimit,0) & "b"
exit function
end if
end if

if length > 0 and boundary <> "" then are there required informations about upload ?
boundary = "--" & boundary
dim head, binary
binary = request.binaryread(length) reads binary data from client

retrieves the upload fields from binary data
set result = separatefields(binary, boundary)
binary = empty clear variables
else
err.raise 10, "getupload", "zero length request ."
end if
else
err.raise 11, "getupload", "no file sent."
end if
else
err.raise 1, "getupload", "bad request method."
end if
set getupload = result
end function


function separatefields(binary, boundary)
dim posopenboundary, poscloseboundary, posendofheader, islastboundary
dim fields
boundary = stringtobinary(boundary)

posopenboundary = instrb(binary, boundary)
poscloseboundary = instrb(posopenboundary + lenb(boundary), binary, boundary, 0)

set fields = createobject("scripting.dictionary")

do while (posopenboundary > 0 and poscloseboundary > 0 and not islastboundary)
header and file/source field data
dim headercontent, fieldcontent
header fields
dim content_disposition, formfieldname, sourcefilename, content_type
helping variables
dim field, twocharsafterendboundary
get end of header
posendofheader = instrb(posopenboundary + len(boundary), binary, stringtobinary(vbcrlf + vbcrlf))

separates field header
headercontent = midb(binary, posopenboundary + lenb(boundary) + 2, posendofheader - posopenboundary - lenb(boundary) - 2)

separates field content
fieldcontent = midb(binary, (posendofheader + 4), poscloseboundary - (posendofheader + 4) - 2)

separates header fields from header
getheadfields binarytostring(headercontent), content_disposition, formfieldname, sourcefilename, content_type

create one field and assign parameters
set field = createuploadfield()
field.name = formfieldname
field.contentdisposition = content_disposition
field.filepath = sourcefilename
field.filename = getfilename(sourcefilename)
field.contenttype = content_type
field.value = fieldcontent
field.length = lenb(fieldcontent)


fields.add formfieldname, field

is this ending boundary ?
twocharsafterendboundary = binarytostring(midb(binary, poscloseboundary + lenb(boundary), 2))
binary.mid(poscloseboundary + len(boundary), 2).string
islastboundary = twocharsafterendboundary = "--"
if not islastboundary then this is not ending boundary - go to next form field.
posopenboundary = poscloseboundary
poscloseboundary = instrb(posopenboundary + lenb(boundary), binary, boundary )
end if
loop
set separatefields = fields
end function

********************************** utilities **********************************
function binarytostring(str)
strto = ""
for i=1 to lenb(str)
if ascb(midb(str, i, 1)) > 127 then
strto = strto & chr(ascb(midb(str, i, 1))*256+ascb(midb(str, i+1, 1)))
i = i + 1
else
strto = strto & chr(ascb(midb(str, i, 1)))
end if
next
binarytostring=strto
end function

function stringtobinary(string)
dim i, b
for i=1 to len(string)
b = b & chrb(asc(mid(string,i,1)))
next
stringtobinary = b
end function

separates header fields from upload header
function getheadfields(byval head, content_disposition, name, filename, content_type)
content_disposition = ltrim(separatefield(head, "content-disposition:", ";"))
name = (separatefield(head, "name=", ";")) ltrim
if left(name, 1) = """" then name = mid(name, 2, len(name) - 2)
filename = (separatefield(head, "filename=", ";")) ltrim
if left(filename, 1) = """" then filename = mid(filename, 2, len(filename) - 2)
content_type = ltrim(separatefield(head, "content-type:", ";"))
end function

separets one filed between sstart and send
function separatefield(from, byval sstart, byval send)
dim posb, pose, sfrom
sfrom = lcase(from)
posb = instr(sfrom, sstart)
if posb > 0 then
posb = posb + len(sstart)
pose = instr(posb, sfrom, send)
if pose = 0 then pose = instr(posb, sfrom, vbcrlf)
if pose = 0 then pose = len(sfrom) + 1
separatefield = mid(from, posb, pose - posb)
else
separatefield = empty
end if
end function

separetes file name from the full path of file
function getfilename(fullpath)
dim pos, posf
posf = 0
for pos = len(fullpath) to 1 step -1
select case mid(fullpath, pos, 1)
case "/", "\": posf = pos + 1: pos = 0
end select
next
if posf = 0 then posf = 1
getfilename = mid(fullpath, posf)
end function
</script>
<script runat=server language=jscript>
//the function creates field object.
function createuploadfield(){ return new uf_init() }
function uf_init(){
this.name = null
this.contentdisposition = null
this.filename = null
this.filepath = null
this.contenttype = null
this.value = null
this.length = null
}
</script>

addphoto.asp
<!--#include file="conn.asp"-->
<!--#include file="inc/domin.asp"-->
<!--#include file="fupload.inc"-->
<%
if request.servervariables("request_method") = "post" then
dim fields
uploadsizelimit=100000
set fields = getupload()
dim field
for each field in fields.items
select case field.name
case "thetext" sss=binarytostring(field.value)
case "type" fff=binarytostring(field.value)
case "submit" submit=binarytostring(field.value)
case "pic"
filename=field.filename
filecontenttype=field.contenttype
filevalue=field.value
end select
next
---------------
if filename<>"" and filecontenttype<>"image/gif" and

filecontenttype<>"image/pjpeg" then
%>
<center>
<br><br>
<font color=red size=3>上传的照片应该为gif或jpg文件!</font><br><br>
<input type="button" value="重填" onclick="history.go( -1 );return

true;">
</center>
<%
else
------------
开始输入
-----------
response.write sss
response.write"<br>"
response.write fff
set rs=server.createobject("adodb.recordset")
sql = "select * from tb where theid is null"
rs.open sql,conn,3,3
rs.addnew
rs("author")=username
rs("thetext")=sss
rs("types")=fff
rs("hits")=1
rs("posttime")=now()
rs("photo").appendchunk filevalue

rs.update
rs.close
%>
<br><br>
<center><font color=red

size=3>成功输入个人基本档案!</font><br><br><form method="post"

action="personinf.asp"><input type="submit" value="返回"></form>
</center>
<%
end if
end if
%>


showpic.asp
<!--#include file="conn.asp"-->
<%
id=request("id")
set rs=server.createobject("adodb.recordset")
sql="select * from tb where theid="&id
rs.open sql,conn,1,3
response.contenttype="image/gif"
response.binarywrite rs("photo")
%>


文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
相关主题
文章页数:[1] 
Google
热门文章
·数据库开发个人总结(ADO.NET小结)-.NET教程,数据库应用
·怎么由DataSet将数据导入Excel?-.NET教程,数据库应用
·动态创建SQL Server数据库、表、存储过程-ASP教程,数据库相关
·Win32环境下动态链接库(DLL)编程原理-.NET教程,数据库应用
·封装的ADO.NET对数据库操作经典类-.NET教程,数据库应用
·在DataGridView中获得DataGridViewCheckBoxColumn的状态-ASP教程,数据库相关
·DataGrid使用心得(附大量代码)-ASP教程,数据库相关
·用代码创建DataGrid的多链接及checkbox事件响应-.NET教程,数据库应用
·ADO.NET 的最佳实践技巧-.NET教程,数据库应用
·转载: 用纯ASP代码实现图片上传并存入数据库中

最新文章
·根据数据表中数据,生成Powerpoint幻灯片-ASP教程,数据库相关
·DataGrid中的按钮反选事件与NamingContainer(命名容器)-downmoon-ASP教程,数据库相关
·使用用VB处理MYSQL数据库中二进制数据问题-.NET教程,VB.Net语言
·关于DataGridView中如何接收处于编辑状态下的当前信息-ASP教程,数据库相关
·在DataGridView中获得DataGridViewCheckBoxColumn的状态-ASP教程,数据库相关
·.net下访问Access数据库需要注意的问题-.NET教程,Asp.Net开发
·ActiveMQ4.1+Spring2.0的POJO JMS方案(上)-.NET教程,数据库应用
·ASP.NET 2.0中直接将Access数据库导入到Excel文件中-.NET教程,Asp.Net开发
·NET(C#)连接各类数据库-集锦-.NET教程,C#语言
·ASP.NET2.0连接SQL Server数据库详解-.NET教程,Asp.Net开发




版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!

特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。
  打印  刷新  关闭
返回首页 |关于我们 | 联系我们 | 付款方式 | 创业联盟 | 虚拟主机 | 资讯中心 | 友情链接 | 网站地图

版权所有 西部数码(www.west263.com)
CopyRight (c) 2002~2006 west263.com all right reserved.
公司地址:四川成都市万和路90号天象大厦4楼 邮编:610031
电话总机:028-86262244 86263048 86263408 86263960 86264018 86267838
售前咨询:总机转201 202 203 204 206 208
售后服务:总机转211 212 213 214
财务咨询:总机转224 223 传真:028-86264041 财务QQ:点击发送消息给对方635483282
售前咨询QQ:点击发送消息给对方2182518 点击发送消息给对方241975952 点击发送消息给对方275026793 点击发送消息给对方408235859
售后服务QQ:点击发送消息给对方17708515 点击发送消息给对方307742704 点击发送消息给对方287976517 点击发送消息给对方363783715
《中华人民共和国增值电信业务经营许可证》编号:川B2-20030065号