zoukankan      html  css  js  c++  java
  • 图片文件上传入SQL库及显示代码 转

    图片文件上传入SQL库代码:
    html页代码:
    <INPUT id="file1" type="file" name="file1" runat="server">
    后台代码:
        Public Class BinaryFile
            ' 文件编号
            Public FileID As Int64
            ' 文件标题
            Public FileTitle As String
            ' 文件内容
            Public FileContents As Byte()
            ' 文件类型
            Public FileType As String
        End Class

                '------------------------------------------上传文件操作开始---------------------------------------------

                Dim objFile As Common.Data.BinaryFile = New Common.Data.BinaryFile
                Dim intLen As Integer
                intLen = file1.PostedFile.ContentLength
                If intLen > 200000 Then
                    Response.Write("<script language='javascript'>alert('上传的文件超出了限定的大小!');history.back();</script>")
                End If
                ReDim objFile.FileContents(intLen)
                file1.PostedFile.InputStream.Read(objFile.FileContents, 0, intLen)
                objFile.FileType = file1.PostedFile.ContentType
                Dim FilePath As String = file1.Value
                If intDocLen <> 0 Then
                    If Mid(file1.PostedFile.ContentType, 1, 5) <> "image" Then
                        Response.Write("<script language=javascript>alert('请上传正确的图片类型!');history.back();</script>")
                        Response.End()
                    End If
                End If
                Dim flag As Integer = objFile.Add(objFile.FileContents, objFile.FileType)
                    If flag = 1 Then
                        Response.Write("<script language=javascript>alert('提交成功!');</script>")
                    Else
                        Response.Write("<script>alert('提交失败!');history.back();</script>")
                        Response.End()
                    End If

                '-----------------------------------------上传文件操作结束---------------------------------------------


    图片文件显示代码:
    html页代码:
        <asp:Image id="Image2" runat="server"></asp:Image>
    后台代码:
        Dim objFile As Common.Data.BinaryFile = New Common.Data.BinaryFile
        Dim CID As Integer = CInt(Trim(Request.QueryString("CID")))
        Dim ds As DataSet = New DataSet
        ds = objFile .Get(CID)

        If IsDBNull(ds.Tables(0).Rows(0).Item("FileType")) = False And Left(CStr(ds.Tables(0).Rows(0).Item("FileType")), 6) = "image/" Then
            Response.ContentType = Convert.ToString(ds.Tables(0).Rows(0).Item("FileType"))
            Response.BinaryWrite(ds.Tables(0).Rows(0).Item("FileContents"))
        Else
            Me.Image.ImageUrl = "images/wu.gif"
        End If

  • 相关阅读:
    [Windows]wmic查看运行进程的参数
    Java8中的foreach跳出循环break/return
    Python Learning(6)字典
    SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(三): 整合阿里云 OSS 服务 -- 上传、下载文件、图片
    SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(四): 整合阿里云 短信服务、整合 JWT 单点登录
    SpringBoot + Vue + ElementUI 实现后台管理系统模板 -- 后端篇(五): 数据表设计、使用 jwt、redis、sms 工具类完善注册登录逻辑
    Servlet、Jsp
    BIO、NIO、AIO
    HashMap (JDK1.8) 分析
    mysql常见笔试题
  • 原文地址:https://www.cnblogs.com/nianshi/p/801475.html
Copyright © 2011-2022 走看看