纯ASP上传图像文件到数据库的最佳例子

2016-01-29 17:18 3 1 收藏

纯ASP上传图像文件到数据库的最佳例子,纯ASP上传图像文件到数据库的最佳例子

【 tulaoshi.com - ASP 】

  getfile.htm
-------------------------
<html

<head
<title保存图片到数据库</title
</head

<body
<b

<p</b你可以找个图片试试,保存完毕后会有提示</p

<form METHOD="POST" ENCTYPE="multipart/form-data" ACTION="savetodb.asp"
  <pEmail : <input NAME="email" VALUE="wangcq@sina.com" size="20"<br
  Picture : <input TYPE="file" NAME="blob"<br
  <input TYPE="submit" NAME="Enter" </p
</form
</body
</html

savetodb.asp
----------------------------------
<%

Response.Buffer = TRUE
Response.Clear
byteCount = Request.TotalBytes

RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")

BuildUploadRequest  RequestBin

email = UploadRequest.Item("email").Item("Value")

contentType =  UploadRequest.Item("blob").Item("ContentType")
filepathname = UploadRequest.Item("blob").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,""))
picture = UploadRequest.Item("blob").Item("Value")

'Response.ContentType = contentType
'Response.binaryWrite picture

set objCn = server.createobject("adodb.connection")
set objRst = server.createobject("adodb.recordset")
objCn.Open "upload"
objrst.Open "pic", objcn, 1,3,2
objrst.addnew
objrst.fields("filename")=filename
objrst.fields("type")="gif"

objrst.fields("what").appendchunk picture
objrst.update
response.write "<a href=showpic.asp?id=" & objrst("id") & "第" & objrst("id") & "个图片。</a"
objrst.close

objCn.close
set objrst=nothing
set objcn = nothing
%
<!--#include file="upload.asp"--

showpic.asp
----------------------------------------
<%
set objCn = server.createobject("adodb.connection")
set objRst = server.createobject("adodb.recordset")
objCn.Open "upload"
objrst.Open "select what from pic where id=" & request("id"), objcn

if not objrst.eof then
    response.binarywrite objrst("what")
end if

objrst.close
objCn.close
set objrst=nothing
set objcn = nothing
%


upload.asp
-------------------------------------------
<%
Sub BuildUploadRequest(RequestBin)
    'Get the boundary
    PosBeg = 1
    PosEnd = InstrB(PosBeg,RequestBin,getByteString(chr(13)))
    boundary = MidB(RequestBin,PosBeg,PosEnd-PosBeg)
    boundaryPos = InstrB(1,RequestBin,boundary)
    'Get all data inside the boundaries
    Do until (boundaryPos=InstrB(RequestBin,boundary & getByteString("--")))
        'Members variable of objects are put in a dictionary object
        Dim UploadControl
        Set UploadControl = CreateObject("Scripting.Dictionary")
        'Get an object name
        Pos = InstrB(BoundaryPos,RequestBin,getByteString("Content-Disposition"))
        Pos = InstrB(Pos,RequestBin,getByteString("name="))
       

来源:https://www.tulaoshi.com/n/20160129/1500934.html

延伸阅读
标签: ASP
  网上介绍用ASP访问INTERBASE数据库的资料很少,经过几天的奋斗终于成功的解决了这个问题.现把部份代码和一些资料贡献给大家. <%@ language="vbscript"%         str1 = "Driver={XTG Systems Interbase6 ODBC driver};uid=sysdba;pwd=masterkey;Data Source=ly" Set conn = Server.Creat...
< %@ Import Namespace="System.Data" % <%@ Import Namespace="System.Data.SQL" % <html < script language="C#" runat="server" '声明C# public DataSet dsCustomer; protected void Page_Load(Object Src, EventArgs E ) { '当打开页面时联结数据库 SQLConnection myConnection = new SQLConnection ("server=sql2....
标签: ASP
  引言 本文针对ASP程序设计中最基础、也是最关键的部分"数据库文件的调用"进行说明,同时谈谈ASP程序设计中数据库文件调用的一些技巧。 ASP简介 ASP(Active Server Pages)是微软于1996年推出的Web应用程序开发技术,它是一种脚本语言、ActiveX组件及HTML语言等的综合,微软把它描述为"一个服务器的脚本环境,在这...
标签: Web开发
用ASP编写网站应用程序时间长了,难免会遇到各式各样的问题,其中 关于如何上传文件到服务器恐怕是遇见最多的问题了,尤其是上传图片,比如你想要在自己的社区里面实现类似网易虚拟社区提供的每日一星的功能,就要提供给网友上传照片的功能。上传图片文件到服务器可以使用各种免费的文件上传组件,使用起来功能虽然很强大,但是由于很...
标签: Web开发
说明:dbf数据库结构要与sql表一致 % Dim conndbf_dbf,Driver_dbf,SourceType_dbf,DBPath_dbf dim Conn_sql ,StrCnn,i,str_dbf dim dbf_table_name,sql_table_name 'dbf数据库名称 dbf_table_name="20005070" 'sql表名称 sql_table_name="zjls" str_dbf="" ' 建立dbfConnection 对...

经验教程

627

收藏

93
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部