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+"文件:"&ofileup.form(strformelement).userfilename&" 大于"&upfilesize\1024&"kb!<br>" else strshortfilename = mid(ofileup.form(strformelement).userfilename,instrrev(ofileup.form(strformelement).userfilename, "\")+1) '取得文件名 strextension = mid(strshortfilename, instrrev(strshortfilename, ".")) '取得扩展名 if strrestrictby = "extension" then '--验证方式为扩展名 'strshortfilename = ofileup.form(strformelement).shortfilename '======检查后缀名==== select case lcase(strextension) case ".jpg", ".gif", ".bmp",".png"
case else flagok=0 ofileup.form(strformelement).delete response.write("<b>错误:</b> 扩展名为 <i>" & strextension & "</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>" & strcontenttype & "</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())&hour(now())&minute(now())&second(now())&rannum&lcase(strextension) ofileup.form(strformelement).saveinvirtual formpath&filename '让文件名不重复,保存文件,这里用的是saveinvirtual方法
'--输出该文件的大小 response.write "<b>大小:</b>"&ofileup.form(strformelement).totalbytes & "<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 对象的方法: set ofileup = server.createobject("softartisans.fileup")
取出表单所有项的方法: for each strformelement in ofileup.form 用 ofileup.form(strformelement)就可以引用每个对象,文件也是这样 注意:如果是多选下拉框,则用ofileup.formex(strformelement) 可以这样来遍历它。 for each strsubitem in ofileup.formex(strformelement) response.write( strsubitem & "<br>") next next
网友评论