您的位置: 首页 > 技术文档 > 网络编程 > 用 SA FileUp 上传多文件
Dataset初步 回到列表 ASP发送邮件的class(完)
 用 SA FileUp 上传多文件

作者:萧萧小雨 时间: 2003-11-07 文档类型:原创 来自:蓝色理想

第 1 页 用 SA FileUp 上传多文件 [1]
第 2 页 用 SA FileUp 上传多文件 [2]
第 3 页 用 SA FileUp 上传多文件 [3]
第 4 页 用 SA FileUp 上传多文件 [4]

<%@ 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
%>

出处:蓝色理想
责任编辑:帅青蛙

上一页 用 SA FileUp 上传多文件 [2] 下一页 用 SA FileUp 上传多文件 [4]

◎进入论坛网络编程版块参加讨论

相关文章
[ASP]利用 xmlhttp 分块上传文件
使用Flash MX 2004创建组件
在 ListBox 组件中应用 HTML
Flash MX 2004对DRK组件兼容性
ColdFusion与FLASH通信轻松入门
作者文章
[asp]让你知道codepage的重要
用 SA FileUp 上传多文件
将数据库的内容生成WORD文档
关键字搜索 常规搜索 推荐文档
热门搜索:CSS Fireworks 设计比赛 网页制作 web标准 用户体验 UE photoshop Dreamweaver Studio8 Flash 手绘 CG
站点最新 站点最新列表
周大福“敬•自然”设计大赛开启
国际体验设计大会7月将在京举行
中国国防科技信息中心标志征集
云计算如何让安全问题可控
云计算是多数企业唯一拥抱互联网的机会
阿里行云
云手机年终巨献,送礼标配299起
阿里巴巴CTO王坚的"云和互联网观"
1499元买真八核 云OS双蛋大促
首届COCO桌面手机主题设计大赛
栏目最新 栏目最新列表
浅谈JavaScript编程语言的编码规范
如何在illustrator中绘制台历
Ps简单绘制一个可爱的铅笔图标
数据同步算法研究
用ps作简单的作品展示页面
CSS定位机制之一:普通流
25个最佳最闪亮的Eclipse开发项目
Illustrator中制作针线缝制文字效果
Photoshop制作印刷凹凸字体
VS2010中创建自定义SQL Rule
>> 分页 首页 前页 后页 尾页 页次:3/41个记录/页 转到 页 共4个记录

蓝色理想版权申明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有。

转载要求:转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。

特别注意:本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有,文章若有侵犯作者版权,请与我们联系,我们将立即删除修改。

您的评论
用户名:  口令:
说明:输入正确的用户名和密码才能参与评论。如果您不是本站会员,你可以注册 为本站会员。
注意:文章中的链接、内容等需要修改的错误,请用报告错误,以利文档及时修改。
不评分 1 2 3 4 5
注意:请不要在评论中含与内容无关的广告链接,违者封ID
请您注意:
·不良评论请用报告管理员,以利管理员及时删除。
·尊重网上道德,遵守中华人民共和国的各项有关法律法规
·承担一切因您的行为而直接或间接导致的民事或刑事法律责任
·本站评论管理人员有权保留或删除其管辖评论中的任意内容
·您在本站发表的作品,本站有权在网站内转载或引用
·参与本评论即表明您已经阅读并接受上述条款
推荐文档 | 打印文档 | 评论文档 | 报告错误  
专业书推荐 更多内容
网站可用性测试及优化指南
《写给大家看的色彩书1》
《跟我去香港》
众妙之门—网站UI 设计之道
《Flex 4.0 RIA开发宝典》
《赢在设计》
犀利开发—jQuery内核详解与实践
作品集 更多内容

杂⑦杂⑧ Gold NORMANA V2