用 SA FileUp 上传多文件(2)
作者:萧萧小雨 来源:蓝色理想 发布时间:2008-07-04 13:44:00
标签:上传,SA,FileUp,组件
<%@ CODEPAGE="936"%>
<%
Server.ScriptTimeOut=5000 '--脚本超时设置为5000
%>
<!--#include file="conn.asp" -->
<%
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp") '--建立SA FileUp Object
'oFileUp.Path = Server.MapPath("/upfile/") '--我这里要自己定义文件名,所以没有使用Path属性,注意这句被注释掉了。
strRestrictBy = "" '--文件验证方式,分为extension和ContentType
iCount=0 '--文件上传数的计数变量
formPath="upfile/" '文件保存位置
'-----------检查是否有在此位置上传的权限-----------这里省略了。
groupID=trim(oFileUp.form("groupID"))
albumID=trim(oFileUp.form("albumID"))
'-----------检查权限完成------
if errMsg="" then '----如果到此还没有错误
For Each strFormElement In oFileUp.Form
If IsObject(oFileUp.Form(strFormElement)) Then '如果是文件
If Not oFileUp.Form(strFormElement).IsEmpty Then '--文件不为空
flagOK=1
'--不是文件或文件大于限制,设置错误信息
If oFileUp.Form(strFormElement).TotalBytes<100 Then
flagOK=0
ElseIf oFileUp.Form(strFormElement).TotalBytes> upFileSize Then
flagOK=0
errMsg=errMsg+"文件:"
errMsg = errMsg & oFileUp.Form(strFormElement).UserFileName
errMsg = errMsg & " 大于"&upFileSize\1024&"KB!<br>"
Else
If strRestrictBy = "extension" Then '--验证方式为扩展名
strShortFileName = mid(oFileUp.Form(strFormElement).UserFileName,InStrRev(oFileUp.Form(strFormElement).UserFileName, "\")+1) '取得文件名
strExtension = Mid(strShortFileName, InStrRev(strShortFileName, ".")) '取得扩展名
'======检查后缀名====
Select Case LCase(strExtension)
Case ".jpg", ".gif", ".bmp",".png"
Case Else
flagOK=0
oFileUp.Form(strFormElement).Delete
Response.Write("<B>错误:</B> 扩展名为 <I>")
Response.Write(strExtension)
Response.Write ( "</I> 的文件不能被上传。<BR>")
End Select
Else '--验证方式为MIME类型
strContentType = oFileUp.Form(strFormElement).ContentType
Select Case LCase(strContentType)
Case "image/gif", "image/jpeg", "image/pjpeg"
Case Else
flagOK=0
oFileUp.Form(strFormElement).Delete
Response.Write("<B>错误:</B> MIME类型为 <I>")
Response.Write (strContentType)
Response.Write ("</I> 的文件不能被上传。<BR>")
End Select
End If '--end if 验证方式
End If 'end if 文件大小判断
If flagOK=1 Then '如果文件通过检查,保存文件,并插入数据库纪录
randomize
ranNum=int(900*rnd)+100
filename=year(now())&month(now())&day(now())
filename = filename &hour(now())&minute(now())
filename = filename&second(now())&ranNum
filename = filename&LCase(strExtension)
oFileUp.Form(strFormElement).SaveInVirtual formPath&filename '让文件名不重复,保存文件,这里用的是SaveInVirtual方法
'--输出服务器上的文件路径
Response.Write oFileUp.Form(strFormElement).ServerName & ":ServerName<BR>"
'--输出客户端的文件路径
Response.Write "<BR><B>文件:</B>"
Response.Write (oFileUp.Form(strFormElement).UserFileName)
Response.Write "<BR>"
'--输出该文件的大小
Response.Write "<B>大小:</B>"&
Response.Write oFileUp.Form(strFormElement).TotalBytes
Response.Write "<BR>"
'===添加文件的信息到数据库里===
myIndex=right(strFormElement,1) '--取得文件的序号,如file1则取得为1,file2取得为2
temp_photoTitle=oFileUp.form("photoTitle"+myIndex) '--这四行取得对应的标题,简介,宽度,高度
temp_photoIntro=oFileUp.form("photoIntro"+myIndex)
temp_photoWidth=oFileUp.form("photoWidth"+myIndex)
temp_photoHeight=oFileUp.form("photoHeight"+myIndex)
'====检查输入,为空则给初值==
temp_photoTitle=replace(trim(temp_photoTitle),"'","''")
if temp_photoTitle="" then
temp_photoTitle="没有填写"
end if
temp_photoIntro=replace(trim(temp_photoIntro),"'","''")
if temp_photoIntro="" then
temp_photoIntro="没有填写"
end if
if temp_photoWidth="" or not IsNumeric(temp_photoWidth) then
temp_photoWidth=160
end if
if temp_photoHeight="" or not IsNumeric(temp_photoHeight) then
temp_photoHeight=120
end if
'===插入数据库===
FileSize=oFileUp.Form(strFormElement).TotalBytes
sql = "insert into TBL_PHOTO(albumID, groupID, userName, addTime, photoFilename, photoTitle, photoIntro, photoClick, photoSize, photoWidth, photoHeight, locked,viewPassword) values(" & albumID & "," & groupID & ",'" & session("userName") & "','" & Now() & "','" & filename & "','" & temp_photoTitle & "','" & temp_photoIntro & "',1," & FileSize & "," & temp_photoWidth & "," & temp_photoHeight & ",'no','')"
conn.execute sql
sql="update TBL_ALBUM set photoCount=photoCount+1 where albumID="&albumID
conn.execute sql
sql="update TBL_GROUP set photoCount=photoCount+1 where groupID="&groupID
conn.execute sql
'===输出上传成功信息===
iCount=iCount+1
End If
Else
Response.Write strFormElement & "对象为空!"
End If '--end if 对象为空
End If '--end if 是否是文件
Next
Set oFileUp = Nothing '删除此对象
end if '--end if 没有错误信息
response.write "<br>"&iCount&" 个文件上传结束!"
response.write "<br><a href='photo_listphoto.asp?albumID="&albumID&"'><B>返回相册</B></a>"
'=====如果有错,输出错误信息=====
if errMsg<>"" then
response.write "<br>"&errMsg
response.write "<INPUT type='button' onClick='history.go(-1)' value='返回' class='myInput'>"
end if
conn.close
set conn=nothing
%>


猜你喜欢
- 我们可以通过mysql命令查看mysql的安装路径:# 以下两个sql任意一个可查询select @@basedir as basePath
- 在进行matplotlib画图的时候,经常会出现这个的报错,虽然知道是因为没有对应的字体的原因,但是,将字体下载后放到目标路径下,仍然没有办
- 在Windows下使用VSCode编译运行,都出现中文乱码的问题,今天我就遇见了这种情况,上网搜了半天也没有找到正确的解决方法,现将我把我的
- 废话不多说,直接开始拉~~~我们总共有 6 只海龟,颜色不同,它们以随机长度移动。首先,我们应该通过输入乌龟的颜色来押注乌龟。第一个越线的乌
- 一、读写excel数据利用pandas可以很方便的读写excel数据1.1 读:data_in = pd.read_excel('M
- 最近在用python处理Excel表格是遇到了一些问题1, xlwt最多只能写入65536行数据, 所以在处理大批量数据的时候没法使用2,
- Python 中有 while 和 for 两种循环机制,其中 while 循环
- 前言前面已经讲述了如何获取股票的k线数据,今天我们来分析一下股票的资金流入情况,股票的上涨和下跌都是由资金推动的,这其中的北上资金就是一个风
- 从学习Python至今,发现很多时候是将Python作为一种工具。特别在文本处理方面,使用起来更是游刃有余。说到文本处理,那么正则表达式必然
- 1、判断多个条件的语句,if为真则执行if后面的语句。2、如果elif是真的,则执行elif,后面的代码块不执行。3、如果if和elif不满
- 解决方案:1、选择Edit Configurations, 删除相关单元测试2、右击__name__ == "__main__&q
- 导读:由于banner一般用于专题类网站,在门户网站的二级页面,用户进来之前,在首页已经对主题有一定的了解和认识,所以banner的作用是在
- Json模块dumps、loads、dump、load函数介绍1、json.dumps() json.dumps()用于将dict
- 1 :普通SQL语句可以用exec执行Select * from tableName exec('select * from tab
- 因为有大家的支持,我们才能做到现在,感谢你们这一路上对我们的支持.在这篇文章中,我们将主要针对MySQL的实用技巧,讲讲面试中相关的问题.1
- 本文实例为大家分享了python实现书法碑帖图片分割的具体代码,供大家参考,具体内容如下一、功能实现效果1、选择要分割的碑帖图片2、选择碑帖
- 一、vscode插件介绍在我们演示插值表达式之前,我们先安装这一个VScode给我们提供的插件,它可以将我们书写好的网页通过服务端口的方式进
- 我就废话不多说了,直接上代码吧!'''python对象销毁(垃圾回收)'''class Po
- 1 通过官网下载MySQL5.6版本压缩包,mysql-5.6.36-winx64.zip;2 在D盘创建目录,比如D:\MySQL,将my
- python中通过引用计数来回收垃圾对象,在某些环形数据结构(树,图……),存在对象间的循环引用,比如树的父节点引用子节点,子节点同时引用父