根据风声文件上传系统修改了部分代码:
第一部分:提交表单页
<script language="JavaScript" type="text/javascript">
<!--
function setFileFileds(num){
for(var i=0,str="";i<num;i++){
str+="<input name=/"strFile"+i+"/" type=/"file/" id=/"strFile"+i+"/" size=40><br>";
}
objFiles.innerHTML=str;
}
//-->
</script>
<form action="upload.asp" enctype="multipart/form-data" name="myinfo" method="post">
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="100" height="25" align="right" bgcolor="#F9F9F9" class="text12">产品标题:</td>
<td><input name="protitle" type="text" id="protitle" size="40"></td>
</tr>
<tr>
<td width="100" height="25" align="right" valign="middle" bgcolor="#F9F9F9" class="text12">上传图片: </td>
<td><span class="text12">
<select name="select" onChange="setFileFileds(this.value)">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
</select>
张(图片格式为gif、jpg,每张图片大小在120K以内)</span></td>
</tr>
<tr>
<td width="100" align="right" valign="middle" bgcolor="#F9F9F9" class="text12"></td>
<td id="objFiles"></td>
</tr>
<tr>
<td width="100" height="25" align="right" bgcolor="#F9F9F9"> </td>
<td height="30" align="right" valign="middle"><input type="submit" name="Submit" value=" 提 交 ">
<input type="reset" name="Submit2" value=" 重 置 "></td>
</tr>
</table>
</form>
<script language="JavaScript">setFileFileds(myinfo.select.value)</script>
第二部分:写入数据库(这是修改的主要内容)upload.asp页内容
<%
'----------------------------------------------------------
'***************** 风声无组件上传类 2.0 *****************
'用法举例:批量上传
'该例主要说明默认模式下FileItem在批量上传中的应用
'以上传附件为例
'下面是上传程序(upload.asp)的代码和注释
'**********************************************************
'----------------------------------------------------------
OPTION EXPLICIT
Server.ScriptTimeOut=5000
%>
<!--#include FILE="UpLoadClass.asp"-->
<!--#include file="conn.asp" -->
<%
dim request2,formPath,formName,intCount,intTemp,protitle,protext,showindex,proclass,upfile,rs,sql
'建立上传对象
set request2=new UpLoadClass
'设置文件允许的附件类型为gif/jpg/rar/zip
request2.FileType="gif/jpg"
'设置服务器文件保存路径
request2.SavePath="../UpLoadFile/"
'打开对象
request2.open()
%>
<html>
<head>
<title>批量上传——风声无组件上传类</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="db_sc8.css" rel="stylesheet" type="text/css">
</head>
<body>
<br>
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td class="text12">
<%
'显示类版本
'response.Write("<br>"&request2.version&"<br>")
'显示文章标题
response.Write("<br>文章标题:"&request2.Form("proTitle"))
'----列出所有上传了的文件开始----
'将记录写入数据库,此为自己新增部分
Set Rs =Server.CreateObject("Adodb.RecordSet")
Sql="select * from product"
rs.open sql,conn,1,3
intCount=0
for intTemp=1 to Ubound(request2.FileItem)
'获取表单文件控件名称,注意FileItem下标从1开始
formName=request2.FileItem(intTemp)
'显示源文件路径与文件名
response.write "<br>"&request2.form(formName&"_Path")&request2.form(formName&"_Name")
'显示文件大小(字节数)
response.write "("&request2.form(formName&"_Size")&") => "
'显示目标文件路径与文件名
response.Write formPath&request2.form(formName)&" "
'显示文件保存状态
select case request2.form(formName&"_Err")
case -1:
response.write "没有文件上传<br>"
case 0:
response.write "上传文件成功<br>"
intCount=intCount+1
case 1:
response.write "文件太大,拒绝上传<br>"
case 2:
response.write "文件格式不对,拒绝上传<br>"
case 3:
response.write "文件太大且格式不对,拒绝上传<br>"
end select
upfile=request2.form(formName)
protitle=request2.Form("protitle")
rs.addnew
rs("propic")=upfile
rs("protitle")=protitle
rs.update
next
'----列出所有上传了的文件结束----
rs.close
set rs=nothing
response.write "<br>"&intCount&" 张图片上传成功! "
response.write "[<a href=""javascript:history.back();"">返回</a>]"
%> </td>
</tr>
</table>
</body>
</html>
<%
'释放上传对象
set request2=nothing
%>
第三部分:风声文件上传类文件 uploadclass.asp 这个未动过,咱也不懂
<%
'----------------------------------------------------------
'***************** 风声无组件上传类 2.0 *****************
'作者:风声
'网站:http://www.17560.net http://www.54nb.com
'邮件:Rumor@17560.net
'版权:版权全体,源代码公开,各种用途均可免费使用
'**********************************************************
'----------------------------------------------------------
Class UpLoadClass
Private p_MaxSize,p_FileType,p_SavePath,p_AutoSave,p_Error
Private objForm,binForm,binItem,strDate,lngTime
Public FormItem,FileItem
Public Property Get Version
Version="Rumor UpLoadClass Version 2.0"
End Property
Public Property Get Error
Error=p_Error
End Property
Public Property Get MaxSize
MaxSize=p_MaxSize
End Property
Public Property Let MaxSize(lngSize)
if isNumeric(lngSize) then
p_MaxSize=clng(lngSize)
end if
End Property
Public Property Get FileType
FileType=p_FileType
End Property
Public Property Let FileType(strType)
p_FileType=strType
End Property
Public Property Get SavePath
SavePath=p_SavePath
End Property
Public Property Let SavePath(strPath)
p_SavePath=replace(strPath,chr(0),"")
End Property
Public Property Get AutoSave
AutoSave=p_AutoSave
End Property
Public Property Let AutoSave(byVal Flag)
select case Flag
case 0:
case 1:
case 2:
case false:Flag=2
case else:Flag=0
end select
p_AutoSave=Flag
End Property
Private Sub Class_Initialize
p_Error = -1
p_MaxSize = 1536000 '最大150K 153600
p_FileType = "jpg/gif"
p_SavePath = ""
p_AutoSave = 0
strDate = replace(cstr(Date()),"-","")
lngTime = clng(timer()*1000)
Set binForm = Server.CreateObject("ADODB.Stream")
Set binItem = Server.CreateObject("ADODB.Stream")
Set objForm = Server.CreateObject("Scripting.Dictionary")
objForm.CompareMode = 1
End Sub
Private Sub Class_Terminate
objForm.RemoveAll
Set objForm = nothing
Set binItem = nothing
binForm.Close()
Set binForm = nothing
End Sub
Public Sub Open()
if p_Error=-1 then
p_Error=0
else
Exit Sub
end if
Dim lngRequestSize,binRequestData,strFormItem,strFileItem
Const strSplit="'"">"
lngRequestSize=Request.TotalBytes
if lngRequestSize<1 then
p_Error=4
Exit Sub
end if
binRequestData=Request.BinaryRead(lngRequestSize)
binForm.Type = 1
binForm.Open
binForm.Write binRequestData
Dim bCrLf,strSeparator,intSeparator
bCrLf=ChrB(13)&ChrB(10)
intSeparator=InstrB(1,binRequestData,bCrLf)-1
strSeparator=LeftB(binRequestData,intSeparator)
Dim p_start,p_end,strItem,strInam,intTemp,strTemp
Dim strFtyp,strFnam,strFext,lngFsiz
p_start=intSeparator+2
Do
p_end =InStrB(p_start,binRequestData,bCrLf&bCrLf)+3
binItem.Type=1
binItem.Open
binForm.Position=p_start
binForm.CopyTo binItem,p_end-p_start
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strItem=binItem.ReadText
binItem.Close()
p_start=p_end
p_end =InStrB(p_start,binRequestData,strSeparator)-1
binItem.Type=1
binItem.Open
binForm.Position=p_start
lngFsiz=p_end-p_start-2
binForm.CopyTo binItem,lngFsiz
intTemp=Instr(39,strItem,"""")
strInam=Mid(strItem,39,intTemp-39)
if Instr(intTemp,strItem,"filename=""")<>0 then
if not objForm.Exists(strInam&"_From") then
strFileItem=strFileItem&strSplit&strInam
if binItem.Size<>0 then
intTemp=intTemp+13
strFtyp=Mid(strItem,Instr(intTemp,strItem,"Content-Type: ")+14)
strTemp=Mid(strItem,intTemp,Instr(intTemp,strItem,"""")-intTemp)
intTemp=InstrRev(strTemp,"/")
strFnam=Mid(strTemp,intTemp+1)
objForm.Add strInam&"_Type",strFtyp
objForm.Add strInam&"_Name",strFnam
objForm.Add strInam&"_Path",Left(strTemp,intTemp)
objForm.Add strInam&"_Size",lngFsiz
if Instr(intTemp,strTemp,".")<>0 then
strFext=Mid(strTemp,InstrRev(strTemp,".")+1)
else
strFext=""
end if
if left(strFtyp,6)="image/" then
binItem.Position=0
binItem.Type=1
strTemp=binItem.read(10)
if strcomp(strTemp,chrb(255) & chrb(216) & chrb(255) & chrb(224) & chrb(0) & chrb(16) & chrb(74) & chrb(70) & chrb(73) & chrb(70),0)=0 then
if Lcase(strFext)<>"jpg" then strFext="jpg"
binItem.Position=3
do while not binItem.EOS
do
intTemp = ascb(binItem.Read(1))
loop while intTemp = 255 and not binItem.EOS
if intTemp < 192 or intTemp > 195 then
binItem.read(Bin2Val(binItem.Read(2))-2)
else
Exit do
end if
do
intTemp = ascb(binItem.Read(1))
loop while intTemp < 255 and not binItem.EOS
loop
binItem.Read(3)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,8),chrb(137) & chrb(80) & chrb(78) & chrb(71) & chrb(13) & chrb(10) & chrb(26) & chrb(10),0)=0 then
if Lcase(strFext)<>"png" then strFext="png"
binItem.Position=18
objForm.Add strInam&"_Width",Bin2Val(binItem.Read(2))
binItem.Read(2)
objForm.Add strInam&"_Height",Bin2Val(binItem.Read(2))
elseif strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(57) & chrb(97),0)=0 or strcomp(leftB(strTemp,6),chrb(71) & chrb(73) & chrb(70) & chrb(56) & chrb(55) & chrb(97),0)=0 then
if Lcase(strFext)<>"gif" then strFext="gif"
binItem.Position=6
objForm.Add strInam&"_Width",BinVal2(binItem.Read(2))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(2))
elseif strcomp(leftB(strTemp,2),chrb(66) & chrb(77),0)=0 then
if Lcase(strFext)<>"bmp" then strFext="bmp"
binItem.Position=18
objForm.Add strInam&"_Width",BinVal2(binItem.Read(4))
objForm.Add strInam&"_Height",BinVal2(binItem.Read(4))
end if
end if
objForm.Add strInam&"_Ext",strFext
objForm.Add strInam&"_From",p_start
intTemp=GetFerr(lngFsiz,strFext)
if p_AutoSave<>2 then
objForm.Add strInam&"_Err",intTemp
if intTemp=0 then
if p_AutoSave=0 then
strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
end if
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
objForm.Add strInam,strFnam
end if
end if
else
objForm.Add strInam&"_Err",-1
end if
end if
else
binItem.Position=0
binItem.Type=2
binItem.Charset="gb2312"
strTemp=binItem.ReadText
if objForm.Exists(strInam) then
objForm(strInam) = objForm(strInam)&","&strTemp
else
strFormItem=strFormItem&strSplit&strInam
objForm.Add strInam,strTemp
end if
end if
binItem.Close()
p_start = p_end+intSeparator+2
loop Until p_start+3>lngRequestSize
FormItem=split(strFormItem,strSplit)
FileItem=split(strFileItem,strSplit)
End Sub
Private Function GetTimeStr()
lngTime=lngTime+1
GetTimeStr=strDate&lngTime
End Function
Private Function GetFerr(lngFsiz,strFext)
dim intFerr
intFerr=0
if lngFsiz>p_MaxSize and p_MaxSize>0 then
if p_Error=0 or p_Error=2 then p_Error=p_Error+1
intFerr=intFerr+1
end if
if Instr(1,LCase("/"&p_FileType&"/"),LCase("/"&strFext&"/"))=0 and p_FileType<>"" then
if p_Error<2 then p_Error=p_Error+2
intFerr=intFerr+2
end if
GetFerr=intFerr
End Function
Public Function Save(Item,strFnam)
Save=false
if objForm.Exists(Item&"_From") then
dim intFerr,strFext
strFext=objForm(Item&"_Ext")
intFerr=GetFerr(objForm(Item&"_Size"),strFext)
if objForm.Exists(Item&"_Err") then
if intFerr=0 then
objForm(Item&"_Err")=0
end if
else
objForm.Add Item&"_Err",intFerr
end if
if intFerr<>0 then Exit Function
if VarType(strFnam)=2 then
select case strFnam
case 0:strFnam=GetTimeStr()
if strFext<>"" then strFnam=strFnam&"."&strFext
case 1:strFnam=objForm(Item&"_Name")
end select
end if
binItem.Type = 1
binItem.Open
binForm.Position = objForm(Item&"_From")
binForm.CopyTo binItem,objForm(Item&"_Size")
binItem.SaveToFile Server.MapPath(p_SavePath&strFnam),2
binItem.Close()
if objForm.Exists(Item) then
objForm(Item)=strFnam
else
objForm.Add Item,strFnam
end if
Save=true
end if
End Function
Public Function GetData(Item)
GetData=""
if objForm.Exists(Item&"_From") then
if GetFerr(objForm(Item&"_Size"),objForm(Item&"_Ext"))<>0 then Exit Function
binForm.Position = objForm(Item&"_From")
GetData=binFormStream.Read(objForm(Item&"_Size"))
end if
End Function
Public Function Form(Item)
if objForm.Exists(Item) then
Form=objForm(Item)
else
Form=""
end if
End Function
Private Function BinVal2(bin)
dim lngValue,i
lngValue = 0
for i = lenb(bin) to 1 step -1
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
BinVal2=lngValue
End Function
Private Function Bin2Val(bin)
dim lngValue,i
lngValue = 0
for i = 1 to lenb(bin)
lngValue = lngValue *256 + ascb(midb(bin,i,1))
next
Bin2Val=lngValue
End Function
End Class
%>