为了建设班级主页,买了个空间,支持SA FileUp组件。
鼓弄了一天,终于有了大致的了解,下面是我的实例,希望对大家有所帮助。
大家可以根据自己的实际情况进行修改,特别是数据库操作部分。
============================================
利用稻香老农的无组件进行多文件上传
请见:
www.blueidea.com/bbs/newsdetail.asp?id=1249535&posts=current
==================================================
本例属于文件和表单项的混合提交。
简单说明:
虽然重点在处理页上,但我觉得有必要介绍一下表单的项目。
本例是相册里像片的上传。
其中的groupID是隐藏域传递的大类的ID
其中的albumID是隐藏域传递的小类的ID
file1–>>file5是文件
photoTitle1–>>photoTitle5 是像片的标题
photoIntro1–>>photoIntro5 是像片的简介
photoWidth1–>>photoWidth5 是像片的宽度
photoHeight1–>>photoHeigth5 是像片的高度
photoSize1–>>photoSize5 是像片的大小。
注意:因本人没有声明变量的习惯,所以大家要是强制声明变量的话,就得自己加了。
===========================================
提交页:主要代码如下
<form name="fileForm" method="post" action="photo_savephoto.asp" enctype="multipart/form-data" onSubmit="return checkForm();">
<INPUT name="groupID" type="hidden" id="groupID"
value="<%=groupID%>" size="10">
<INPUT name="albumID" type="hidden" id="albumID"
value="<%=albumID%>" size="10">
上传说明:最多可以同时上传五个文件,其中标题最多30字,简介200字。
<table width="96%" align="center" cellpadding="4" cellspacing="2">
<tr align="center" valign="middle">
<td align="left" bgcolor="#F4CECE" id="upid">文件1</td>
<td height="29" align="left" bgcolor="#F4CECE" id="upid">
<INPUT name="file1" type="file" class="myInput" size="20">
宽: <INPUT name="photoWidth1" type="text" class="input-disabled" id="photoWidth1" size="5" readonly="">
高: <INPUT name="photoHeight1" type="text" class="input-disabled" id="photoHeight1" size="5" readonly="">
大小:<INPUT name="fileSize1" type="text" class="input-disabled" id="fileSize1" size="5" readonly="">
</td>
</tr>
<tr align="center" valign="middle">
<td colspan="2" align="left" bgcolor="#FDF2F2" id="upid">
标题: <INPUT name="photoTitle1" type="text" class="myInput" id="photoTitle1" size="40">
<BR>
简介:<TEXTAREA name="photoIntro1" cols="60" rows="5" class="myInput" id="photoIntro1"></TEXTAREA>
</td>
</tr>
。。。。。。。
<tr align="center" valign="middle" bgcolor="#F4CECE">
<td height="24" colspan="2">
<input name="Submit" type="submit" class="myButton" value="开始上传">
<input name="Submit2" type="reset" class="myButton" value="重新填写">
</td>
</tr>
</table>
</form>
下面的script是我用来检查图片属性的。其中检查了图片的宽度,高度,大小,是否是图片。
<SCRIPT language="JavaScript">
<!–
<–ubbcodetab–> <–/ubbcodetab–>var upFileSize=<%=upFileSize%>;
//–>
</SCRIPT>
<SCRIPT language="JavaScript" src="photo_addphoto.js"></SCRIPT>
<TABLE width="98%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
<TR>
<TD height="1"><img src="images/add.gif" id="loadPhoto" onload="if(!firstLoad)showInfo();"></TD>
</TR>
</TABLE>
photo_addphoto.js
代码拷贝框
以下是引用片段: var firstLoad=true; var mycount; function checkForm() { var filePath; var fileNumber=0; //想上传的文件个数 for(mycount=1;mycount<=5;mycount++) if(eval("fileForm.file"+mycount+".value!=”")) //检查文件后缀、标题和简介 { eval("filePath=fileForm.file"+mycount+".value;") if(isPic(filePath,mycount)==false) return false; if(eval("fileForm.photoTitle"+mycount+".value==”") || eval("fileForm.photoTitle"+mycount+".value.length>30")) { alert("第"+mycount+"个相片的标题为空或超过30字!"); return false; } if(eval("fileForm.photoIntro"+mycount+".value==”") || eval("fileForm.photoIntro"+mycount+".value.length>200")) { alert("第"+mycount+"个相片的简介为空或超过200字!"); return false; } fileNumber++; } if(fileNumber==0) { alert("你没有选择任何一个图片文件!不能提交!"); return false; } return photoInfo(); //检查图片属性,提交表单 } function photoInfo() { //fileForm.submit.disabled=true; mycount=0; photoInfo2(); //共执行5次photoInfo2() for(var i=1;i<=4;i++) { setTimeout("photoInfo2()",i*500); } setTimeout("checkFileSize()",3000); return false; } function photoInfo2() { firstLoad=false; mycount++; if(eval("fileForm.file"+mycount+".value!=”")) eval("loadPhoto.src=fileForm.file"+mycount+".value;"); else eval("fileForm.fileSize"+mycount+".value=’no’;"); } function showInfo() { eval("fileForm.photoWidth"+mycount+".value=loadPhoto.offsetWidth;"); eval("fileForm.photoHeight"+mycount+".value=loadPhoto.offsetHeight;"); eval("fileForm.fileSize"+mycount+".value=loadPhoto.fileSize;"); } function isPic(filePath,mycount){ var temp; var ExtList = ".jpg.gif.bmp.png"; var the_ext = filePath.substr(filePath.lastIndexOf(".")+1).toLowerCase(); if (ExtList.indexOf(the_ext)==-1){ alert("第"+mycount+"个文件不是图片,请选择图片文件!"); return false; } return true; } function checkFileSize() { for(mycount=1;mycount<=5;mycount++) if(eval("fileForm.fileSize"+mycount+".value")>upFileSize) //upFileSize 来自于photo_addphoto.asp { alert("第"+mycount+"个文件大于"+Math.round(upFileSize/1024)+" KB!"); return false; } fileForm.Submit.disabled=true; fileForm.submit(); //提交表单 } |
这里只写出了一个文件的相关输入框,其他四个类似。
说明一点,并不是有5 个的限制,只是我这里只写了5个。
其中的photo_addphoto.js在客户端对图片进行一遍检查,不是图片的会提示,大小超过限制的也会提示。
这样就避免了用户经过耐心的等待后才被告诉不合标准的烦恼。
<%@ 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
<–ubbcodetab–> <–/ubbcodetab–>If IsObject(oFileUp.Form(strFormElement)) Then ‘如果是文件
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>If Not oFileUp.Form(strFormElement).IsEmpty Then ‘–文件不为空
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>flagOK=1
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘–不是文件或文件大于限制,设置错误信息
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>If oFileUp.Form(strFormElement).TotalBytes<100 Then
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>flagOK=0
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>ElseIf oFileUp.Form(strFormElement).TotalBytes> upFileSize Then
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>flagOK=0
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>errMsg=errMsg+"文件:"
errMsg = errMsg & oFileUp.Form(strFormElement).UserFileName
errMsg = errMsg & " 大于"&upFileSize\1024&"KB!<br>"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Else
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>If strRestrictBy = "extension" Then ‘–验证方式为扩展名
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>strShortFileName = mid(oFileUp.Form(strFormElement).UserFileName,InStrRev(oFileUp.Form(strFormElement).UserFileName, "\")+1) ‘取得文件名
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>strExtension = Mid(strShortFileName, InStrRev(strShortFileName, ".")) ‘取得扩展名
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘======检查后缀名====
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Select Case LCase(strExtension)
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Case ".jpg", ".gif", ".bmp",".png"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Case Else
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>flagOK=0
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>oFileUp.Form(strFormElement).Delete
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Response.Write("<B>错误:</B> 扩展名为 <I>")
Response.Write(strExtension)
Response.Write ( "</I> 的文件不能被上传。<BR>")
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>End Select
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Else ‘–验证方式为MIME类型
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>strContentType = oFileUp.Form(strFormElement).ContentType
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Select Case LCase(strContentType)
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Case "image/gif", "image/jpeg", "image/pjpeg"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Case Else
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>flagOK=0
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>oFileUp.Form(strFormElement).Delete
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Response.Write("<B>错误:</B> MIME类型为 <I>")
Response.Write (strContentType)
Response.Write ("</I> 的文件不能被上传。<BR>")
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>End Select
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>End If ‘–end if 验证方式
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>End If ‘end if 文件大小判断
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>If flagOK=1 Then ‘如果文件通过检查,保存文件,并插入数据库纪录
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>randomize
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>ranNum=int(900*rnd)+100
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>filename=year(now())&month(now())&day(now())
filename = filename &hour(now())&minute(now())
filename = filename&second(now())&ranNum
filename = filename&LCase(strExtension)
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>oFileUp.Form(strFormElement).SaveInVirtual formPath&filename ‘让文件名不重复,保存文件,这里用的是SaveInVirtual方法
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘–输出服务器上的文件路径
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Response.Write oFileUp.Form(strFormElement).ServerName & ":ServerName<BR>"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘–输出客户端的文件路径
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Response.Write "<BR><B>文件:</B>"
Response.Write (oFileUp.Form(strFormElement).UserFileName)
Response.Write "<BR>"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘–输出该文件的大小
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Response.Write "<B>大小:</B>"&
Response.Write oFileUp.Form(strFormElement).TotalBytes
Response.Write "<BR>"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘===添加文件的信息到数据库里===
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>myIndex=right(strFormElement,1) ‘–取得文件的序号,如file1则取得为1,file2取得为2
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoTitle=oFileUp.form("photoTitle"+myIndex) ‘–这四行取得对应的标题,简介,宽度,高度
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoIntro=oFileUp.form("photoIntro"+myIndex)
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoWidth=oFileUp.form("photoWidth"+myIndex)
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoHeight=oFileUp.form("photoHeight"+myIndex)
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘====检查输入,为空则给初值==
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoTitle=replace(trim(temp_photoTitle),"’","”")
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>if temp_photoTitle="" then
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoTitle="没有填写"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>end if
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoIntro=replace(trim(temp_photoIntro),"’","”")
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>if temp_photoIntro="" then
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoIntro="没有填写"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>end if
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>if temp_photoWidth="" or not IsNumeric(temp_photoWidth) then
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoWidth=160
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>end if
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>if temp_photoHeight="" or not IsNumeric(temp_photoHeight) then
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>temp_photoHeight=120
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>end if
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘===插入数据库===
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>FileSize=oFileUp.Form(strFormElement).TotalBytes
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>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’,”)"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>conn.execute sql
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>sql="update TBL_ALBUM set photoCount=photoCount+1 where albumID="&albumID
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>conn.execute sql
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>sql="update TBL_GROUP set photoCount=photoCount+1 where groupID="&groupID
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>conn.execute sql<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>‘===输出上传成功信息===
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>iCount=iCount+1
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>End If
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Else
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Response.Write strFormElement & "对象为空!"
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>End If ‘–end if 对象为空
<–ubbcodetab–> <–/ubbcodetab–>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>"
‘=====如果有错,输出错误信息=====<–ubbcodetab–> <–/ubbcodetab–>
if errMsg<>"" then
<–ubbcodetab–> <–/ubbcodetab–>response.write "<br>"&errMsg
<–ubbcodetab–> <–/ubbcodetab–>response.write "<INPUT type=’button’ onClick=’history.go(-1)’ value=’返回’ class=’myInput’>"
end if
conn.close
set conn=nothing
%>
看完了实例,下面对SA FileUP的属性和方法进行简单的介绍,免得大家初次接触感到发晕。
这些是我觉得比较常用的,例句和注释都是按我的理解写的。
如果大家在应用中发现有什么问题,请指出。谢谢。
建立SA FileUp 对象的方法:
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
取出表单所有项的方法:
For Each strFormElement In oFileUp.Form
<–ubbcodetab–> <–/ubbcodetab–>用 oFileUp.Form(strFormElement)就可以引用每个对象,文件也是这样
<–ubbcodetab–> <–/ubbcodetab–>注意:如果是多选下拉框,则用oFileUp.FormEx(strFormElement)
<–ubbcodetab–> <–/ubbcodetab–>可以这样来遍历它。
<–ubbcodetab–> <–/ubbcodetab–>For Each strSubItem In oFileUp.FormEx(strFormElement)
<–ubbcodetab–> <–/ubbcodetab–><–ubbcodetab–> <–/ubbcodetab–>Response.Write( strSubItem & "<BR>")
<–ubbcodetab–> <–/ubbcodetab–>Next
Next
ContentType属性:
oFileUp.Form(strFormElement).ContentType
可以得到文件的MIME类型
IsEmpty属性
oFileUp.Form(strFormElement).IsEmpty
可以知道用户是不是指定了一个无效的文件
MaxBytes属性
oFileUp.Form(strFormElement).MaxBytes=30000
指定文件的限制,单位为Byte,如果超过它,那么只存储MaxBytes指定的大小。其余舍弃。
ServerName属性
oFileUp.Form(strFormElement).ServerName
可以得到文件保存到服务器的完整路径。
ShortFilename属性
oFileUp.Form(strFormElement).ShortFilename
可以得到客户端的文件名,注意只是文件名,我这里没有用,因为报错。呵呵。
UserFilename属性
oFileUp.Form(strFormElement).UserFileName
可以得到客户端文件的完整路径。可以输出一下给用户看看。
TotalBytes属性
oFileUp.Form(strFormElement).TotalBytes
可以得到文件的大小,单位为Byte
SaveInVirtual(路径)方法
oFileUp.Form(strFormElement).SaveInVirtual "upfile/"
oFileUp.Form(strFormElement).SaveInVirtual "upfile/aa.abc"
如果只指定了路径,则保留原文件名,否则按指定指定文件名保存
服务器管理员可以禁止掉其他所有方法,但这个一定会留的。
SaveAs (文件名)方法
oFileUp.Form(strFormElement).SaveAs "C:\aa\a.tmp"
如果没有指定路径,只是指定了文件名,那么将用Path属性指定的路径。
Path属性一会介绍。
Save方法
oFileUp.Path="D:\wwwroot\abc\upfile\"
注意必须是真实路径,可以用Server.MapPath来转换虚拟路径。
oFileUp.Form(strFormElement).Save
不能指定文件名喽。
注意:Path属性必须在提到任何表单项之前,建议放在
Set oFileUp = Server.CreateObject("SoftArtisans.FileUp")
的后面。前提是你用的话。
Delete (文件名,可选)
oFileUp.Form(strFormElement).Delete
从服务器上删除文件,如果不指定文件名,则删除当前的文件。
如果指定的话,必须是文件的完整路径。
Flush方法
oFileUp.Flush
当你不想保存任何东西的时候,可以用它来放弃全部的输入流。
评论前必须登录!
注册