高分紧急求救!ASP如何用无组件方法上传图片及信息至数据库?

mseliqin 2004-12-06 02:29:40
小弟的想法是将图片及信息一次提交上传至access数据库的一个表中,以后在页面中通过超连接,传递信息参数在数据库中找到图片,并在页面中显示出来.最好提供源码或相关的文章.谢了.
...全文
240 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
sifn 2004-12-10
  • 打赏
  • 举报
回复
<%
声明:此上传类是在化境编程界发布的无组件上传类的基础上修改的.
'在与化境编程界无组件上传类相比,速度快了将近50倍,当上传4M大小的文件时
'服务器只需要10秒就可以处理完,是目前最快的无组件上传程序,当前版本为0.96
'源代码公开,免费使用,对于商业用途,请与作者联系
'文件属性:例如上传文件为c:\myfile\doc.txt
'FileName 文件名 字符串 "doc.txt"
'FileSize 文件大小 数值 1210
'FileType 文件类型 字符串 "text/plain"
'FileExt 文件扩展名 字符串 "txt"
'FilePath 文件原路径 字符串 "c:\myfile"
'使用时注意事项:
'由于Scripting.Dictionary区分大小写,所以在网页及ASP页的项目名都要相同的大小
'写,如果人习惯用大写或小写,为了防止出错的话,可以把
'sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'改为
'(小写者)sFormName = LCase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'(大写者)sFormName = UCase(Mid (sinfo,iFindStart,iFindEnd-iFindStart))
'**********************************************************************
'----------------------------------------------------------------------
dim oUpFileStream

Class upload_file

dim Form,File,Version

Private Sub Class_Initialize
'定义变量
dim RequestBinDate,sStart,bCrLf,sInfo,iInfoStart,iInfoEnd,tStream,iStart,oFileInfo
dim iFileSize,sFilePath,sFileType,sFormvalue,sFileName
dim iFindStart,iFindEnd
dim iFormStart,iFormEnd,sFormName
'代码开始
Version="无组件上传类 Version 0.96"
set Form = Server.CreateObject("Scripting.Dictionary")
set File = Server.CreateObject("Scripting.Dictionary")
if Request.TotalBytes < 1 then Exit Sub
set tStream = Server.CreateObject("adodb.stream")
set oUpFileStream = Server.CreateObject("adodb.stream")
oUpFileStream.Type = 1
oUpFileStream.Mode = 3
oUpFileStream.Open
oUpFileStream.Write Request.BinaryRead(Request.TotalBytes)
oUpFileStream.Position=0
RequestBinDate = oUpFileStream.Read
iFormEnd = oUpFileStream.Size
bCrLf = chrB(13) & chrB(10)
'取得每个项目之间的分隔符
sStart = MidB(RequestBinDate,1, InStrB(1,RequestBinDate,bCrLf)-1)
iStart = LenB (sStart)
iFormStart = iStart+2
'分解项目
Do
iInfoEnd = InStrB(iFormStart,RequestBinDate,bCrLf & bCrLf)+3
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iFormStart
oUpFileStream.CopyTo tStream,iInfoEnd-iFormStart
tStream.Position = 0
tStream.Type = 2
tStream.Charset ="gb2312"
sInfo = tStream.ReadText
'取得表单项目名称
iFormStart = InStrB(iInfoEnd,RequestBinDate,sStart)-1
iFindStart = InStr(22,sInfo,"name=""",1)+6
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFormName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
'如果是文件
if InStr (45,sInfo,"filename=""",1) > 0 then
set oFileInfo= new FileInfo
'取得文件属性
iFindStart = InStr(iFindEnd,sInfo,"filename=""",1)+10
iFindEnd = InStr(iFindStart,sInfo,"""",1)
sFileName = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileName = GetFileName(sFileName)
oFileInfo.FilePath = GetFilePath(sFileName)
oFileInfo.FileExt = GetFileExt(sFileName)
iFindStart = InStr(iFindEnd,sInfo,"Content-Type: ",1)+14
iFindEnd = InStr(iFindStart,sInfo,vbCr)
oFileInfo.FileType = Mid (sinfo,iFindStart,iFindEnd-iFindStart)
oFileInfo.FileStart = iInfoEnd
oFileInfo.FileSize = iFormStart -iInfoEnd -2
oFileInfo.FormName = sFormName
file.add sFormName,oFileInfo
else
'如果是表单项目
tStream.Close
tStream.Type = 1
tStream.Mode = 3
tStream.Open
oUpFileStream.Position = iInfoEnd
oUpFileStream.CopyTo tStream,iFormStart-iInfoEnd-2
tStream.Position = 0
tStream.Type = 2
tStream.Charset = "gb2312"
sFormvalue = tStream.ReadText
form.Add sFormName,sFormvalue
end if
tStream.Close
iFormStart = iFormStart+iStart+2
'如果到文件尾了就退出
loop until (iFormStart+2) = iFormEnd
RequestBinDate=""
set tStream = nothing
End Sub

Private Sub Class_Terminate
'清除变量及对像
if not Request.TotalBytes<1 then
oUpFileStream.Close
set oUpFileStream =nothing
end if
Form.RemoveAll
File.RemoveAll
set Form=nothing
set File=nothing
End Sub

'取得文件路径
Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

'取得文件名
Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

'取得扩展名
Private function GetFileExt(FullPath)
If FullPath <> "" Then
GetFileExt = mid(FullPath,InStrRev(FullPath, ".")+1)
Else
GetFileExt = ""
End If
End function

End Class

'文件属性类
Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileType,FileStart,FileExt
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
FileType = ""
FileExt = ""
End Sub

'保存文件方法
Public function SaveToFile(FullPath)
dim oFileStream,ErrorChar,i
SaveToFile=1
if trim(fullpath)="" or right(fullpath,1)="/" then exit function
set oFileStream=CreateObject("Adodb.Stream")
oFileStream.Type=1
oFileStream.Mode=3
oFileStream.Open
oUpFileStream.position=FileStart
oUpFileStream.copyto oFileStream,FileSize
oFileStream.SaveToFile FullPath,2
oFileStream.Close
set oFileStream=nothing
SaveToFile=0
end function
End Class
%>
QQ19440242
ruyunluck 2004-12-10
  • 打赏
  • 举报
回复
我刚开始也是用这个方法,走了许多弯路,建议不要用这个方法。把图片地址保存到数据库中。当然如果用于邮件发送还是可以。这是我的一点体会。
liuyangxuan 2004-12-10
  • 打赏
  • 举报
回复
为什么天天有人总是问个问题?
tongrong515 2004-12-10
  • 打赏
  • 举报
回复
请你加我的QQ咯!我发给你咯!286627998
gu1dai 2004-12-10
  • 打赏
  • 举报
回复

yb2008 2004-12-10
  • 打赏
  • 举报
回复
尽量不要把图片写到数据库中,传到指定的文件夹就可以了,把图片名称写入到数据库中!

http://www.hc189.com/upload.rar
tigerhu76 2004-12-10
  • 打赏
  • 举报
回复
mark
明珠佩佩 2004-12-10
  • 打赏
  • 举报
回复
往SQL数据库上传的完整代码,连接部分我就不写了

'upload.asp
<html>
<body>
<center>   
<form name="mainForm" enctype="multipart/form-data" action="process.asp" method=post>     
<input type=file name=mefile><br>   
<input type=submit name=ok value="OK">   
</form>
</center>
</body>
</html>

'process.asp
<%
response.buffer=true
formsize=request.totalbytes
formdata=request.binaryread(formsize)
bncrlf=chrB(13) & chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
mydata=midb(formdata,datastart,dataend)

set connGraph=Server.CreateObject("ADODB.connection")
connGraph.ConnectionString = "driver={SQL Server};server=PIONEER-BIMY;uid=sa;pwd=20040808;database=VSOA"
connGraph.Open

set rec=server.createobject("ADODB.recordset")
rec.Open "SELECT * FROM [images] where id is null",connGraph,1,3
rec.addnew
rec("img").appendchunk mydata
rec.update
rec.close

set rec=nothing
set connGraph=nothing
%>

'show.asp
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>

<body>
<IMG SRC="showing.asp?id=5">
</body>

</html>

'showing.asp
<%
set connGraph=Server.CreateObject("ADODB.connection")
connGraph.ConnectionString = "driver={SQL Server};server=PIONEER-BIMY;uid=sa;pwd=20040808;database=VSOA"
connGraph.Open

set rec=server.createobject("ADODB.recordset")
strsql="select img from images where id= "& trim(request("id"))
rec.open strsql,connGraph,1,1
Response.ContentType = "image/*"
Response.BinaryWrite rec("img").getChunk(7500000)
rec.close

set rec=nothing
set connGraph=nothing
%>


chunling2 2004-12-10
  • 打赏
  • 举报
回复
我也收藏一下
  • 打赏
  • 举报
回复
每个图片一个response.clear
mseliqin 2004-12-09
  • 打赏
  • 举报
回复
自己顶一下,这几天太郁闷了.在楼上 fangq(那一夜,你让我失眠!!)大虾的帮助下,上传成功,单显示却出了问题,我的显示是这样写的:由两个页面组成,第一个页面根据其他关系得到图片的id号,然后用
<img src="xxx.asp?id=xxx"> 传道另一页面读出access中的数据,显示在第一个页面,但是无论id号是多少,都显示数据库中的第一条记录,如果删除第一条记录,图片就不显示了.源码就不写了,就是楼上提供的源码.请问,各位大侠,这是什么地方有错,块块帮帮我吧.
huamulan 2004-12-06
  • 打赏
  • 举报
回复
网上有很多源码的,如化境无组件上传、无惧无组件上传、先锋无组件上传

搜索一下,均提供上传到数据库的示例源码
fangq 2004-12-06
  • 打赏
  • 举报
回复
源码如下:

-------------------------写入access-----------
<%
response.buffer=true
formsize=request.totalbytes
formdata=request.binaryread(formsize)
bncrlf=chrB(13) & chrB(10)
divider=leftB(formdata,clng(instrb(formdata,bncrlf))-1)
datastart=instrb(formdata,bncrlf & bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
mydata=midb(formdata,datastart,dataend)
set conn=Server.CreateObject("ADODB.Connection")
conn.open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("fangqing.mdb")
set rec=server.createobject("ADODB.recordset")
rec.Open "SELECT * from [fangqing] where id is null",conn,1,3
rec.addnew
rec("img").appendchunk mydata
rec.update
rec.close
set rec=nothing
set connGraph=nothing
%>

------------------------------读access---------------------
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("fangqing.mdb")
set rs = server.CreateObject("ADODB.Recordset")
sql="select * from fangqing where id="&request("id")
rs.open sql,conn,1,3
Response.ContentType = "image/*"
Response.BinaryWrite rs("img").getChunk(7500000)
rs.close
set rs=nothing
set conn=nothing
%>

--------------------------显示images----------------

<img src="xs.asp?id=10">
welunzhu 2004-12-06
  • 打赏
  • 举报
回复
不要把圖片寫到數據庫中去,這樣很損庫的

你只要把連接地址寫到庫中就可以阿


圖片還是專門上傳到一個(upfiles )中就好啊
yqh1314 2004-12-06
  • 打赏
  • 举报
回复
很不错呢!
  • 打赏
  • 举报
回复
http://blog.csdn.net/liuxiaoyi666
Clove 2004-12-06
  • 打赏
  • 举报
回复
搞个File类型的,使用二进制写入数据库就好了
不过别忘了记录文件名,文件大小类型
iuhxq 2004-12-06
  • 打赏
  • 举报
回复
这个太多了啊,看看偶这个:http://blog.csdn.net/iuhxq/archive/2004/06/03/20194.aspx

把里面的上传提取出来就行了,很方便的!
ckxp 2004-12-06
  • 打赏
  • 举报
回复
http://www0.ccidnet.com/tech/web/2000/04/26/58_632.html
http://www.kupage.com/webdesign/7/20031017/1651460000027pkxd20u.htm
内容概要:本文系统研究了构网型变流器的正负序阻抗解耦特性及其在弱电网环境下的稳定性表现,重点依托Matlab/Simulink仿真平台,构建了详细的阻抗数学模型,设计了解耦控制策略,并采用小信号扫频法进行频域辨识与稳定性验证。研究深入探讨了构网型变流器与传统跟网型逆变器在正负序阻抗特性上的本质差异,结合虚拟同步发电机(VSG)等先进控制技术,分析其在抑制宽频带振荡、削弱锁相环动态耦合等方面的优越性。文中不仅提供了完整的仿真模型与MATLAB代码实现,还整合了光伏、风电、储能、微电网等多类新能源系统的阻抗建模与稳定性分析资源,形成了一套面向新型电力系统稳定性的综合性技术资料体系,具有较强的科研复现与工程参考价值。; 适合人群:面向具备电力电子、电力系统自动化、新能源并网等专业背景的研究生、高校教师及工程技术人员,特别适用于从事阻抗建模、小干扰稳定性分析、宽频振荡机理研究以及撰写高水平学术论文的科研工作者。; 使用场景及目标:①掌握构网型变流器正负序阻抗建模与扫频辨识的仿真方法;②深入理解VSG等构网型控制在弱电网中提升稳定性的内在机理;③复现顶刊论文中的阻抗分析流程与稳定性判据应用;④利用提供的成熟模型与代码加速科研进程,支撑课题研究与学术成果产出。; 阅读建议:建议结合文中提供的Simulink模型与MATLAB代码,按照“理论建模—仿真搭建—扫频激励—频响提取—Nyquist判据分析”的完整流程进行实践操作,重点关注扫频信号的注入方式、频率范围设置及阻抗曲线的物理意义解读,并参考博士论文复现案例深化对复杂动态耦合问题的理解。

28,403

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧