asp无组件上传并插入到数据库里

来源:爱问cpu 时间:2008-10-24 10:04:00 



<%
  Response.Buffer = True
  Server.ScriptTimeOut=9999999
  On Error Resume Next

%>
<!--#include file="conn.asp"-->
<!--#include file="function.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<meta content="all" name="robots" />
<style type="text/css">
<!--
body,input {font-size:12px;}
-->
</style>
<title>ASP文件上传</title>
</head>
<body id="body">
<%
  checkuser()
 
  ExtName = "xls"    '允许扩展名
  SavePath = "upload"          '保存路径
  If Right(SavePath,1)<>"/" Then SavePath=SavePath&"/" '在目录后加(/)
  CheckAndCreateFolder(SavePath)

  UpLoadAll_a = Request.TotalBytes '取得客户端全部内容
  If(UpLoadAll_a>0) Then
    Set UploadStream_c = Server.CreateObject("ADODB.Stream")
    UploadStream_c.Type = 1
    UploadStream_c.Open
    UploadStream_c.Write Request.BinaryRead(UpLoadAll_a)
    UploadStream_c.Position = 0

    FormDataAll_d = UploadStream_c.Read
    CrLf_e = chrB(13)&chrB(10)
    FormStart_f = InStrB(FormDataAll_d,CrLf_e)
    FormEnd_g = InStrB(FormStart_f+1,FormDataAll_d,CrLf_e)

    Set FormStream_h = Server.Createobject("ADODB.Stream")
    FormStream_h.Type = 1
    FormStream_h.Open
    UploadStream_c.Position = FormStart_f + 1
    UploadStream_c.CopyTo FormStream_h,FormEnd_g-FormStart_f-3
    FormStream_h.Position = 0
    FormStream_h.Type = 2
    FormStream_h.CharSet = "GB2312"
    FormStreamText_i = FormStream_h.Readtext
    FormStream_h.Close

    FileName_j = Mid(FormStreamText_i,InstrRev(FormStreamText_i,"")+1,FormEnd_g)

    If(CheckFileExt(FileName_j,ExtName)) Then
      SaveFile = Server.MapPath(SavePath & FileName_j)

      If Err Then
        Response.Write "文件上传: <span style=""color:red;"">文件上传出错!</span> <a href=""" & Request.ServerVariables("URL") &""">重新上传文件</a><br />"
        Err.Clear
      Else
        SaveFile = CheckFileExists(SaveFile)
 
  SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"")+1)
  session("file")=SaveFileName
 
   k=Instrb(FormDataAll_d,CrLf_e&CrLf_e)+4
        l=Instrb(k+1,FormDataAll_d,leftB(FormDataAll_d,FormStart_f-1))-k-2
        FormStream_h.Type=1
        FormStream_h.Open
        UploadStream_c.Position=k-1
        UploadStream_c.CopyTo FormStream_h,l
        FormStream_h.SaveToFile SaveFile,2
       
        SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"")+1)
 
  Dim Conn1,Driver1,DBPath1,Rs1,Sql1
  ' 建立Connection对象
  Set Conn1 = Server.CreateObject("ADODB.Connection")
  Driver1 = "Driver={Microsoft Excel Driver (*.xls)};"
  DBPath1 = "DBQ=" & Server.MapPath("upload/"&SaveFileName)

  '调用Open 方法打开数据库
  Conn1.Open Driver1 & DBPath1

  Sql1="Select * From [Sheet1$] "
  Set Rs1=Conn1.Execute(Sql1)
 
  IF Rs1.Eof And Rs1.Bof Then
  Response.write "没有找到您需要的数据!!"
  Else
  Do While Not Rs1.EOF
 
   '插入到数据库中
  
  
    OpenDataBase "select * from abc"
    
     if len(rs1(0))=7 then
     
      ctime=left(rs1(0),4)
     else
  
      ctime=left(rs1(0),5)
     end if
   
     rs.addnew
     rs("time")=ctime
     rs.update
     CloseDataBase()
   
    
  Rs1.MoveNext
  Loop
  End IF
 
  Rs1.Close
  Set Rs1=nothing
  Conn1.Close
  Set Conn1=Nothing
 
  '插入到数据库中结束

 Response.write "文件上传: <span style=""color:red;"">" & SaveFileName & " </span>文件上传成功!<a href='choise.asp''>继续上传文件</a><br />"
      End If
    Else
      Response.write "文件上传: <span style=""color:red;"">文件格式不正确!</span> <a href=""" & Request.ServerVariables("URL") &""">重新上传文件</a><br />"
    End If

  Else
%>
<script language="Javascript">
<!--
function ValidInput()
{
   
if(document.upform.upfile.value=="")
  {
    alert("请选择上传文件!")
    document.upform.upfile.focus()
    return false
  }
  return true
}
// -->
</script>
<form action='<%= Request.ServerVariables("URL") %>' method='post' name="upform" onsubmit="return ValidInput()"  enctype="multipart/form-data">
文件上传:
<input type='file' name='upfile' size="40"> <input type='submit' value="上传">
</form>
<%
  End if
  Set FormStream_h = Nothing
  UploadStream.Close
  Set UploadStream = Nothing
%>
</body>
</html>

标签:
0
投稿

猜你喜欢

  • 大家都对vertical-align的各说各话

    2008-06-19 12:11:00
  • ul设置浮动后不能自适应高度

    2011-01-25 12:48:00
  • 使用PHP实现生成HTML静态页面

    2023-11-14 11:14:41
  • ThinkPHP学习笔记(一)ThinkPHP部署

    2023-09-09 12:42:16
  • 分析MySQL抛出异常的几种常见解决方式

    2024-01-16 14:00:59
  • 详解Python3操作Mongodb简明易懂教程

    2023-07-20 00:20:05
  • 解决python3 urllib中urlopen报错的问题

    2022-01-11 10:33:32
  • Python用正则表达式实现爬取古诗文网站信息

    2021-08-30 07:12:51
  • Python语法学习之进程池与进程锁详解

    2021-09-01 23:16:17
  • Flask框架中request、请求钩子、上下文用法分析

    2022-04-17 23:05:08
  • 浅谈Golang Slice切片如何扩容的实现

    2024-04-29 13:06:28
  • Django使用redis缓存服务器的实现代码示例

    2022-12-15 09:16:28
  • Go使用sync.Map来解决map的并发操作问题

    2024-04-29 13:05:57
  • 利用Python实现RSA加密解密方法实例

    2023-10-07 03:10:58
  • Python基于mysql实现学生管理系统

    2024-01-24 05:57:47
  • SQL Serve数据库到DB2连接服务器的实现过程全解

    2010-08-31 15:06:00
  • pycharm 配置svn的图文教程(手把手教你)

    2022-10-21 18:47:47
  • golang gorm错误处理事务以及日志用法示例

    2024-04-25 13:18:50
  • mysql5在rhel5下乱码问题及解决方法

    2010-12-03 16:26:00
  • Vue Echarts实现实时大屏动态数据显示

    2024-04-27 15:52:02
  • asp之家 网络编程 m.aspxhome.com