| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 835 人关注过本帖
标题:无组件图片上伟到服务器中的文件夹 谁能解析一下
只看楼主 加入收藏
毅逊
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2006-8-16
收藏
 问题点数:0 回复次数:3 
无组件图片上伟到服务器中的文件夹 谁能解析一下

add_OK.asp

<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="conn.asp" -->
<% '自动编号
Set rs_Max = Server.CreateObject("ADODB.Recordset")
sql_max = "SELECT Max(ID) as MaxNO FROM DB_bookinfo"
rs_Max.open sql_max,conn,1,3
MaxNO=rs_Max("MaxNO")+1
%>
<%
'从一个完整路径中取出文件名称
function getFileName(strPath)
If strPath<>"" Then
getFileName = mid(strPath,instrrev(strPath,"\")+1)
Else
response.Write("请选择上传的文件!")
response.End()
End If
end function
dim Obj_Come, Obj_Go, Data_B, Data_C
dim posB, posE, posSB, posSE,Enter
dim strPath, strFileName, strContentType
Enter = chrb(13)&chrb(10) '定义一个单字节的回车换行符
set Obj_Come = server.CreateObject("adodb.stream")
Obj_Come.Type = 1 '指定返回数据类型为二进制类型
Obj_Come.Mode = 3 '指定打开模式为读写
Obj_Come.Open
Obj_Come.Write Request.BinaryRead(Request.TotalBytes) '以二进制码方式读取客户端POST数据
Obj_Come.Position = 0
Data_B = Obj_Come.Read
set Obj_Go = server.CreateObject("adodb.stream")
Obj_Go.Type = 1 '指定返回数据类型为二进制类型
Obj_Go.Mode = 3 '指定打开模式为读写
Obj_Go.Open
posB = 1
posB = instrb(posB,Data_B,Enter)
posE = instrb(posB+1,Data_B,Enter)
Obj_Come.Position = posB+1
Obj_Come.CopyTo Obj_Go,posE-posB-2
Obj_Go.Position = 0
Obj_Go.Type = 2
Obj_Go.Charset = "gb2312"
Data_C = Obj_Go.ReadText
Obj_Go.Close
posSB = 1
posSB = instr(posSB,Data_C,"filename=""") + len("filename=""")
posSE = instr(posSB,Data_C,"""")
if posSE > posSB then
strPath = mid(Data_C,posSB,posSE-posSB) '获取文件完整路径
posB = posE
posE = instrb(posB+1,Data_B,Enter)
Obj_Go.Type = 1
Obj_Go.Mode = 3
Obj_Go.Open
Obj_Come.Position = posB
Obj_Come.CopyTo Obj_Go,posE-posB-1
Obj_Go.Position = 0
Obj_Go.Type = 2
Obj_Go.Charset = "gb2312"
Data_C = Obj_Go.ReadText
Obj_Go.Close
strContentType = mid(Data_C,16) '获取文件类型
posB = posE+2
posE = instrb(posB+1,Data_B,Enter)
Obj_Go.Type = 1
Obj_Go.Mode = 3
Obj_Go.Open
Obj_Come.Position = posB+1
Obj_Come.CopyTo Obj_Go,posE-posB-2
Obj_Go.Position = 0
Data_C = Obj_Go.Read
Obj_Go.Close
set rs = server.CreateObject("adodb.recordset")
sql = "select * from DB_bookinfo"
rs.Open sql,conn,1,3
rs.AddNew
rs.Fields("ID").Value=MaxNo
rs.Fields("FileName").Value=getFileName(strPath)
rs.Fields("bookname").Value = Session("bookname")
rs.Fields("cover").AppendChunk Data_C
rs.Update
rs.Close
set rs = nothing
session.Abandon()
%>
<script language="javascript">
alert("图书信息添加成功!");
</script>
<%end if
set Obj_Go = nothing
Obj_Come.Close
session.Abandon()
'保存文件
Set Rs = Server.CreateObject("Adodb.RecordSet")
Sql1 = "select * from DB_bookinfo where id="&MaxNo
Rs.Open Sql1,Conn,1,3
Set MyStream=Server.CreateObject("Adodb.Stream")
MyStream.Type = 1
MyStream.Open
MyStream.Write rs("cover").GetChunk(rs("cover").ActualSize) '将数据写入Stream对象中
MyStream.SaveToFile server.MapPath("Upload")&"\" & Rs("FileName") '保存文件
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>
<script language="javascript">
document.location.href="index.asp"
</script>

conn.asp

<%
set conn=server.CreateObject("ADODB.Connection")
sql="Driver={SQL Server};server=(local);uid=sa;database=db_database08"
conn.open(sql)
%>


index.asp

<%@language="VBScript"%>
<html>
<head>
<title>上传文件到服务器</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet">
<style type="text/css">
<!--
body {
margin-left: 0px;
}
.style5 {color: #666666}
.style6 {
color: #FF0000;
font-size: 18pt;
font-family: "幼圆";
font-weight: bold;
}
-->
</style>
</head>

<body>
<table width="701" height="84" border="0" cellpadding="-2" cellspacing="-2">
<tr>
<td width="715" height="85" valign="bottom" background="login.gif">&nbsp;</td>
</tr>
</table>
<table width="701" height="25" border="0" cellpadding="-2" cellspacing="-2" background="images/navigate.gif">
<tr>
<td width="26"><div align="center"></div></td>
<td width="73"><a href="#" target="main">已出版图书</a></td>
<td width="78"><div align="center"><a href="goodbook_main.asp" target="main">推荐图书</a></div></td>
<td width="98"><div align="center"><a href="willbook_main.asp" target="main">即将出版图书</a></div></td>
<td width="75"><div align="center"><a href="error_main.asp" target="main">勘误发布</a></div></td>
<td width="94"><div align="center"><a href="newbook.asp" target="main">新书公告</a></div></td>
<td width="89"><div align="center"></div> <div align="center"><a href="gsdt_main.asp" target="main">公司动态</a></div></td>
<td width="76"><div align="center"><a href="gs_introduce.asp" target="main">公司介绍</a></div></td>
<td width="92"><div align="center"><a href="zdtj_main.asp" target="main">重点推荐图书</a></div></td>
</tr>
</table>
<script language="javascript">
function Mysubmit()
{form1.submit();}
</script>
<%session("SaveSession")=""%>
<table>
<tr>
<td width="2"></td>
<td>
<table width="694" border="1" align="left" cellpadding="-2" cellspacing="-2" bordercolor="#CAE4FF" bordercolordark="#FFFFFF">
<form name="form1" method="POST" action="SaveSession.asp">
<tr>
<td width="74" height="25" bgcolor="#DDEEFF">&nbsp;书  名:</td>
<td bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="bookname" type="text" class="Style_upload" onBlur="Mysubmit()" value="<%=Session("bookname")%>" size="40">
</span></td>
<td width="82" bgcolor="#DDEEFF">&nbsp;书  号:</td>
<td bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="bookID" type="text" class="Sytle_text" id="bookID">
</span></td>
</tr>
<tr>
<td width="74" height="25" bgcolor="#DDEEFF">&nbsp;所属丛书:</td>
<td bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="series" type="text" class="Style_upload" id="series">
</span></td>
<td width="82" bgcolor="#DDEEFF">&nbsp;当前版次:</td>
<td bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="edition" type="text" class="Sytle_text" id="edition">

</span></td>
</tr>
<tr>
<td width="74" height="25" bgcolor="#DDEEFF">&nbsp;作  者:</td>
<td width="335" bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="writer" type="text" class="Style_upload" id="writer">
</span></td>
<td width="82" bgcolor="#DDEEFF"> &nbsp;发行日期:</td>
<td width="171" bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="pDate" type="text" class="Sytle_text" id="pDate">
</span></td>
</tr>
<tr>
<td width="74" height="25" bgcolor="#DDEEFF">&nbsp;出&nbsp;版&nbsp;社:</td>
<td bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="TPI" type="text" class="Style_upload" id="TPI">
</span></td>
<td width="82" bgcolor="#DDEEFF">&nbsp;价  格:</td>
<td bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="price2" type="text" class="Sytle_text" id="price2">
(元)</span></td>
</tr>
<tr>
<td width="74" height="25" bgcolor="#DDEEFF">&nbsp;图书简介:</td>
<td bgcolor="#F0F8FF"><span class="style5">&nbsp;
<input name="cover" type="text" class="Style_upload" id="cover">
</span></td>
<td width="82" bgcolor="#DDEEFF">&nbsp;是否新书:</td>
<td bgcolor="#F0F8FF"> 
<input name="isNew" type="checkbox" id="isNew" value="1" checked></td>
</tr>
</form>
<form name="form" action="add_OK.asp" enctype="multipart/form-data" method="post">
<tr>
<td width="74" bgcolor="#DDEEFF">&nbsp;封面文件:</td>
<td colspan="3" bgcolor="#F0F8FF"> &nbsp;
<input name="file1" type="file" class="Sytle_auto" size="70"> </td>
</tr>
<tr bgcolor="#ddeeFF">
<td height="38" colspan="4"><div align="center">
<input name="Button" type="submit" class="Style_button" value="保存">
<input name="Submit2" type="button" class="Style_button" value="重置" onClick="JScript:form1.reset();">
<input name="Submit3" type="button" class="Style_button" value="关闭" onClick="JScript:window.close()">
</div></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>

SaveSession.asp

<%
Session("bookname")=request.Form("bookname")
response.Redirect("index.asp")
%>



Upload.asp



<%@LANGUAGE="VBSCRIPT"%>
<%
'从一个完整路径中取出文件名称
function getFileName(strPath)
If strPath<>"" Then
getFileName = mid(strPath,instrrev(strPath,"\")+1)
Else
response.Write("请选择上传的文件!")
response.End()
End If
end function
if request.ServerVariables("REQUEST_METHOD") = "POST" then
dim Obj_Come, Obj_Go, Data_B, Data_C
dim posB, posE, posSB, posSE,Enter
dim strPath, strFileName, strContentType
Enter = chrb(13)&chrb(10) '定义一个单字节的回车换行符
set Obj_Come = server.CreateObject("adodb.stream")
Obj_Come.Type = 1 '指定返回数据类型 adTypeBinary=1,adTypeText=2
Obj_Come.Mode = 3 '指定打开模式 adModeRead=1,adModeWrite=2,adModeReadWrite=3
Obj_Come.Open
Obj_Come.Write request.BinaryRead(request.TotalBytes)
'限制文件的大小
FormData=Request.BinaryRead(FormSize) '以二进制码方式读取客户端POST数据
FormSize=Request.TotalBytes '取得客户端响应的数据的字节大小
If FormSize/1024>20000 Then
response.Write("您上传的文件超出规定的范围,请重新上传!")
response.End()
End If
Obj_Come.Position = 0
Data_B = Obj_Come.Read
set Obj_Go = server.CreateObject("adodb.stream")
Obj_Go.Type = 1
Obj_Go.Mode = 3
Obj_Go.Open
posB = 1
posB = instrb(posB,Data_B,Enter)
posE = instrb(posB+1,Data_B,Enter)
Obj_Come.Position = posB+1
Obj_Come.CopyTo Obj_Go,posE-posB-2
Obj_Go.Position = 0
Obj_Go.Type = 2
Obj_Go.Charset = "gb2312"
Data_C = Obj_Go.ReadText
Obj_Go.Close
posSB = 1
posSB = instr(posSB,Data_C,"filename=""") + len("filename=""")
posSE = instr(posSB,Data_C,"""")
if posSE > posSB then
strPath = mid(Data_C,posSB,posSE-posSB) '获取文件完整路径
posB = posE
posE = instrb(posB+1,Data_B,Enter)
Obj_Go.Type = 1
Obj_Go.Mode = 3
Obj_Go.Open
Obj_Come.Position = posB
Obj_Come.CopyTo Obj_Go,posE-posB-1
Obj_Go.Position = 0
Obj_Go.Type = 2
Obj_Go.Charset = "gb2312"
Data_C = Obj_Go.ReadText
Obj_Go.Close
strContentType = mid(Data_C,16) '获取文件类型
posB = posE+2
posE = instrb(posB+1,Data_B,Enter)
Obj_Go.Type = 1
Obj_Go.Mode = 3
Obj_Go.Open
Obj_Come.Position = posB+1
Obj_Come.CopyTo Obj_Go,posE-posB-2
Obj_Go.Position = 0
Data_C = Obj_Go.Read
Obj_Go.Close
dim conn, rs, sql,cnstr
set conn = server.CreateObject("adodb.connection")
'定义数据库连接字符串
cnstr = "driver={Microsoft Access Driver (*.mdb)};dbq=" & server.MapPath("upload.mdb")
conn.Open cnstr
set rs = server.CreateObject("adodb.recordset")
sql = "select * from DBimage"
rs.Open sql,conn,1,3
rs.AddNew
rs.Fields("FileName").Value=getFileName(strPath)
rs.Fields("content-type").Value = strContentType
rs.Fields("Info").Value = Session("Img_Info")
rs.Fields("dTime").value=now()
rs.Fields("image").AppendChunk Data_C
rs.Update
rs.Close
set rs = nothing
conn.Close
set conn = nothing%>
<script language="javascript">
alert("图片上传成功!");
opener.location.reload();
window.close();
</script>
<%else
response.Write("没有上传图片!" & "<br>")
end if
set Obj_Go = nothing
Obj_Come.Close
set Obj_Come = nothing
else%>
<html>
<head>
<title>图片上传!</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="style.css" rel="stylesheet">
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
}
.style1 {color: #C60001}
.style2 {color: #669999}
-->
</style></head>

<body>
<table width="421" height="260" border="0" cellpadding="-2" cellspacing="-2"
background="images/file/upload.gif">
<tr>
<td width="421" valign="top"><table width="100%" height="83" border="0" cellpadding="-2" cellspacing="-2">
<tr>
<td height="83">&nbsp;</td>
</tr>
</table>
<table width="83%" border="0" align="center" cellpadding="-2" cellspacing="-2">
<tr>
<td width="13%" height="27"><div align="center" class="style1">描述:</div></td>
<td width="100%" height="25" valign="bottom">
<table>
<script language="javascript">
function Mysubmit()
{form1.submit();}
</script>
<tr>
<td valign="bottom">
<form name="form1" action="Img_info.asp" method="post">
<input name="Img_Info" type="text" class="Style_upload" onBlur="Mysubmit()" value="<%=Session("Img_Info")%>" size="40">
</form></td>
</tr>
</table> </td>
</tr>
<form name="form" action="upload.asp" enctype="multipart/form-data" method="post">
<tr>
<td height="32"><div align="center" class="style1">文件:</div></td>
<td height="25">
<input name="file1" type="file" class="Style_upload" size="30"></td>
</tr>
<tr>
<td colspan="2"><div align="center">
<br>
<input name="submit" type="submit" class="Style_button_del" value="上传图片">
<input name="myclose" type="button" class="Style_button_del" id="myclose"
value="关闭窗口" onClick="javascrip:window.close()">
</div></td>
</tr>
</form>
</table>
</td>
</tr>
</table>
</body>
</html>
<%end if
%>

搜索更多相关主题的帖子: 服务器 组件 文件 解析 
2006-08-16 14:42
在编程中沦落
Rank: 2
等 级:新手上路
威 望:4
帖 子:411
专家分:0
注 册:2005-12-25
收藏
得分:0 
能把代码整理得清楚些吗?

2006-08-16 16:56
zhoujianwei
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2006-7-3
收藏
得分:0 
是啊,太乱了,看的我眼都花了

期待和你交流
2006-08-16 21:44
tsfy2003
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-7-31
收藏
得分:0 
字符都没了
的确看不太懂
2006-08-16 23:10
快速回复:无组件图片上伟到服务器中的文件夹 谁能解析一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039538 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved