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

abc安于现状111

abc安于现状111

2016-01-29 17:18

纯ASP上传图像文件到数据库的最佳例子,纯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="))
       
展开更多 50%)
分享

猜你喜欢

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

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

基于ACCESS数据库的纯asp论坛制作心得

ASP
基于ACCESS数据库的纯asp论坛制作心得

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

轻松实现将上传图片到数据库

ASP
轻松实现将上传图片到数据库

一个用asp+存取数据库的例子

ASP
一个用asp+存取数据库的例子

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

JDBC数据库访问例子(1)

Java JAVA基础
JDBC数据库访问例子(1)

JDBC数据库访问例子(2)

Java JAVA基础
JDBC数据库访问例子(2)

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Photoshop基础教程:用批处理功能处理海量照片

Photoshop基础教程:用批处理功能处理海量照片

中文虚拟域名实现(3) (环境:中文NT)

中文虚拟域名实现(3) (环境:中文NT)
下拉加载更多内容 ↓