仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2490|回复: 18
打印 上一主题 下一主题

[学习教程] ASP网站制作之ASP完成多图片上传到指定的目次并存到数...

[复制链接]
再见西城 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:30:53 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Access是一种桌面数据库,只适合数据量少的应用,在处理少量数据和单机访问的数据库时是很好的,效率也很高。但是它的同时访问客户端不能多于4个。access数据库有一定的极限,如果数据达到100M左右,很容易造成服务器iis假死,或者消耗掉服务器的内存导致服务器崩溃。上传|数据|数据库     关于图片上传的例子在网上有良多文章和原代码。然而每次上服装论坛阅读帖子的时分都是看到良多网友对图片上传感应头疼和费事。其实这个成绩也是已经让我感应头疼。也看过了很多的文章和代码。如今我写的这篇文章是把我对照喜好的一篇代码和动网里的高手对这篇代码优化后再加上我增添一些代码联合出来的!呵呵,其实这篇文章是沾了写这篇代码的人(稻喷鼻居士)和动网里那些高手的光。:)
  好了,不说空话了。入手下手来搭建所需求的情况和数据布局!
  先新建一个名字叫photo的文件夹。(我在这里就是把图片上传到这个文件夹里的。)创立一个名字叫database的数据库。再接着创立一个名字叫sFile的表。内外设计四个字段分离是id(int),image(varchar),image1(varchar),image2(varchar)。我这里用的数据库是SQL。
  相干的文件
  register.asp
<html>
<head>
<title>文件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="save.asp">
<table width="50%" border="1" cellspacing="0" cellpadding="0" align="center">
<tr>
<td width="20%"><a href="#" >图片上传</a></td>
<td width="80%">
<input type="text" name="myface">
<input type="text" name="myface1">
<input type="text" name="myface2">
(此处用户不用填图片上传后主动生成) </td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="重设">
</td>
</tr>
</table>
</form>
</body>
</html>
  reg_upload.asp
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" href="CSS/style.css" type="text/css">
</head>
<body leftmargin="0" topmargin="0" >
  <br>
<br>
<br>
<table width="90%" border="0" align="center" bgcolor="#000000" height="152" cellspacing="1">
<tr>
<td height="34" align="center" bgcolor="#FFFFFF"><font color="#FFFF33"><b><font size="4" color="#000000">选择图片</font></b></font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<form name="form" method="post" action="upfile.asp" enctype="multipart/form-data" >
<input type="hidden" name="filepath" value="photo">
<input type="hidden" name="act" value="upload">
<input type="file" name="file1" size="30"><br>
<input type="file" name="file2" size="30"><br>
<input type="file" name="file3" size="30">

<input type="submit" name="Submit" value="粘 贴" class="tl">
</form>
</td>
</tr>
</table>
</body>
</html>
  upfile.asp
<!--#include FILE="upload.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<%
dim arr(3)
dim upload,file,formName,formPath,iCount,filename,fileExt,i
set upload=new upload_5xSoft ''''创立上传对象

formPath=upload.form("filepath")
''''在目次后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
iCount=0
i=0
for each formName in upload.file ''''列出一切上传了的文件
set file=upload.file(formName) ''''生成一个文件对象

if file.filesize<0 then
response.write "<font size=2>请先选择你要上传的图片 [ <a href=# onclick=history.go(-1)>从头上传</a> ]</font>"
response.end
end if

if file.filesize>100000 then
response.write "<font size=2>图片巨细超越了限制 [ <a href=# onclick=history.go(-1)>从头上传</a> ]</font>"
response.end
end if
if fileEXT<>".gif" and fileEXT<>".jpg" then
response.write "<font size=2>文件格局不合错误 [ <a href=# onclick=history.go(-1)>从头上传</a> ]</font>"
response.end
end if

fileExt=lcase(right(file.filename,4))
filename=formPath&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&file.FileName
arr(i)=filename
i=i+1

if file.FileSize>0 then ''''假如 FileSize > 0 申明有文件数据
file.SaveAs Server.mappath(filename) ''''保留文件
'' response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" 胜利!<br>"

iCount=iCount+1
end if
set file=nothing
next
if instr(arr(0),".")=0 and instr(arr(1),".")=0 and instr(arr(2),".")=0 then
response.write "<font size=2>请先选择你要上传的图片 [ <a href=# onclick=history.go(-1)>从头上传</a> ]</font>"
response.end
end if
if instr(arr(0),".")<>0 then
response.write "<script>opener.document.forms[0].myface.value=''" & arr(0) & "''</script>"
else
response.write "<script>opener.document.forms[0].myface.value=''''</script>"
end if
if instr(arr(1),".")<>0 then
response.write "<script>opener.document.forms[0].myface1.value=''" & arr(1) & "''</script>"
else
response.write "<script>opener.document.forms[0].myface1.value=''''</script>"
end if
if instr(arr(2),".")<>0 then
response.write "<script>opener.document.forms[0].myface2.value=''" & arr(2) & "''</script>"
else
response.write "<script>opener.document.forms[0].myface2.value='''' </script>"
end if
set upload=nothing ''''删除此对象

session("upface")="done"

Htmend iCount&" 个文件上传停止!"

sub HtmEnd(Msg)
set upload=nothing
response.write "<html><head><meta http-equiv=''Refresh'' content=''3 url=""javascript:window.close();""''></head><body><center><br><br>文件上传胜利<br>感谢你的撑持!<br>本窗口三秒后主动封闭</center></body></html>"
response.end
end sub
%>
</body>
</html>
  upload.inc
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_5xSoft_Stream

Class upload_5xSoft

dim Form,File,Version

Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version=""
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function

Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=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 toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class

Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>
  save.asp
<% dim dsn,conn
dsn="driver={sql server};server=127.0.0.1;uid=sa;pwd=;database=database"
set conn=server.createobject("adodb.connection")
conn.open dsn
%>
<% dim file,file1,file2
file=trim(request.form("myface"))
file1=trim(request.form("myface1"))
file2=trim(request.form("myface2"))
set rs=server.createobject("adodb.recordset")
sql="Insert Into sFile(image,image1,image2) Values(''"& file &"'',''"& file1&"'',''"& file2&"'')"
conn.execute(sql)
response.redirect "ok.asp"
%>
结论:和PHP一样,ASP简单而易于维护,很适合小型网站应用,通过DCOM和MTS技术,ASP甚至还可以完成小规模的企业应用,但ASP的致命缺点就是不支持跨平台的系统,在大型项目开发和维护上非常困难。
飘飘悠悠 该用户已被删除
沙发
发表于 2015-2-4 00:13:50 | 只看该作者
Response:从字面上讲是“响应”,因此这个是服务端向客户端发送东西的,例如Response.Write
小魔女 该用户已被删除
板凳
发表于 2015-2-9 08:20:46 | 只看该作者
Server:这个表示的服务器,操作服务器的一些东西使用这个,如Server.Mappath转换服务器路径,Server.CreateObject实例化一个组件
简单生活 该用户已被删除
地板
发表于 2015-2-26 09:54:24 | 只看该作者
运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写,使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行。
谁可相欹 该用户已被删除
5#
发表于 2015-3-4 22:10:57 | 只看该作者
尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。
莫相离 该用户已被删除
6#
发表于 2015-3-10 04:07:16 | 只看该作者
尽管MS自己讲C#内核中更多的象VC,但实际上我还是认为它和Java更象一些吧。首先它是面向对象的编程语言,而不是一种脚本,所以它具有面向对象编程语言的一切特性,比如封装性、继承性、多态性等等,这就解决了刚才谈到的ASP的那些弱点。
精灵巫婆 该用户已被删除
7#
发表于 2015-3-17 04:12:08 | 只看该作者
ASP.Net和ASP的最大区别在于编程思维的转换,而不仅仅在于功能的增强。ASP使用VBS/JS这样的脚本语言混合html来编程,而那些脚本语言属于弱类型、面向结构的编程语言,而非面向对象,这就明显产生以下几个问题:
再现理想 该用户已被删除
8#
发表于 2015-3-24 09:06:43 | 只看该作者
弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。
金色的骷髅 该用户已被删除
9#
发表于 2015-3-31 04:28:26 | 只看该作者
交流是必要的,不管是生活还是学习我们都要试着去交流,通过交流我们可以学到很多我们自己本身所没有的知识,可以分享别人的经验甚至经历。
若天明 该用户已被删除
10#
发表于 2015-4-1 04:35:27 | 只看该作者
Session:这个存储跟客户端会话过程的数据,默认20分钟失效
只想知道 该用户已被删除
11#
发表于 2015-4-2 21:46:41 | 只看该作者
代码的可重用性差:由于是面向结构的编程方式,并且混合html,所以可能页面原型修改一点,整个程序都需要修改,更别提代码重用了。
12#
发表于 2015-4-7 15:27:43 | 只看该作者
我想问如何掌握学习节奏(先学什么再学什么)最好详细点?
活着的死人 该用户已被删除
13#
发表于 2015-4-21 21:10:43 | 只看该作者
ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
乐观 该用户已被删除
14#
发表于 2015-5-7 18:32:05 | 只看该作者
运用经典的例子。并且自己可以用他来实现一些简单的系统。如果可以对他进行进一步的修改,找出你觉得可以提高性能的地方,加上自己的设计,那就更上一个层次了,也就会真正地感到有所收获。
海妖 该用户已被删除
15#
发表于 2015-6-15 03:34:15 | 只看该作者
最近在学asp,不要问我为什么不直接学.net,因为公司网站是asp做的所以有这个需要,卖了本书asp入门到精通,对里面的六大内置对象老是记不住,还有很多属性和方法看的头晕。
蒙在股里 该用户已被删除
16#
发表于 2015-6-28 18:57:04 | 只看该作者
运用经典的例子。并且自己可以用他来实现一些简单的系统。如果可以对他进行进一步的修改,找出你觉得可以提高性能的地方,加上自己的设计,那就更上一个层次了,也就会真正地感到有所收获。
老尸 该用户已被删除
17#
发表于 2015-7-8 23:40:44 | 只看该作者
交流是必要的,不管是生活还是学习我们都要试着去交流,通过交流我们可以学到很多我们自己本身所没有的知识,可以分享别人的经验甚至经历。
小妖女 该用户已被删除
18#
发表于 2015-7-17 05:50:34 | 只看该作者
你可以通过继承已有的对象最大限度保护你以前的投资。并且C#和C++、Java一样提供了完善的调试/纠错体系。
不帅 该用户已被删除
19#
发表于 2015-9-28 12:10:14 | 只看该作者
哪些内置对象是可以跳过的,或者哪些属性和方法是用不到的?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-4-20 20:46

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表