• 文本与图像上传到数据库


    1.upload.asp方法
    <head>
    <script language=vbscript>
        function checkinfo()
           if (document1.form1.picture.value<>"") then
             if (Instr(1,document.form1.picture.value,".")<=0) or (Instr(1,document.form1.picture.value,"\")<=0)  or ((Instr(1,document.form1.picture.value,"bmp")<=0) and (Instr(1,document.form1.picture.value,"gif")<=0) and  (Instr(1,document.form1.picture.value,"jpg")<=0)) then
                msgbox('图片格式不正确,请重写!')
                document.form1.picture.focus()
                document.form1.picture.select(this)
                window.even.returnvalue=false
                exit function
              end if    
              form2.submit
              if document.form1.picture1.value<>" " then
                form1.submit
              end if
         end function   
    </script>
    </head>
    <form name="form1" ENCTYPE="multiport/form-data" Action="upimage.asp" Method="POST" target="_blank">
      新闻图片:<input name="picture" TYPE="file" size=40>
    </form>
    <form method="POST" action="uptext.asp" name="form2" target="_blank">新闻内容:
    <input name="text" type="text" size=40>
    <p><input type="button" value="提交" name="B1" onclick="checkinfo()">
    <input type="reset" value="清除" name="B2">

    2.上传文本页面
    <%
      text=request("text")
      set rs=Server.CreateObject("ADODB.Recordset")
      sql="select * from newtable2"
      rs.Open sql,conn,1,3
      rs.AddNew
      rs.("text")=text
      rs.Update
      rs.Close
      response.write text
    %>
    <p align="center"><a href="javascript.Close()">关闭窗口</a></p>

    3.上传图像页面
    注:用rs的appendchunk方法存储图像
    <%
      FormSize=Request.TotalBytes
      FormData=Request.BinaryRead(FormSize)
      function ImageUp(formsize,formdata)
        bnctrf=chrb(13) & chrb(10)
        divider=leftb(formdata,instrb(formdata,bnctrf)-1)
        datastart=instrb(formdata,bnctrf & bnctrf)+4
        dataend=instrb(formdata,datastart,dataend)
      end function
      Image=ImageUp(FormSize,FormData)
      set rs=Server.Create("adodb.recordset")
    %>
    <#include file="data.inc"-->
    <%
      sql="select top 1 * from newstable2 order by id desc"
      rs.open sql.conn,1,3
      rs("picture").appendchunk Image
      re.Update
    %>
    <img src=showimg.asp>id=<%=rs("id")%>>
    <%
      rs.Close
    %>
  • 相关阅读:
    MongoVUE 使用教程
    Mongo
    thinkPHP
    从关系型数据库到非关系型数据库
    boost 文件系统
    boost 随机数发生器
    CString/string 区别及其转化
    boost uuid
    使用命令行解析php文件
    Log4PHP日志库使用
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2035755.html
Copyright © 2020-2023  润新知