我给你一段代码
这是我做的一个网站中遇到的
<!--#include virtual="/Public/Date_Connection.asp" -->
<!--#include virtual="/Public/Messagebox.asp" -->
<!--#include virtual="/Public/Redirect.asp" -->
<%
SQL = "Select * from CyUpFile where ModuleName='公司产品'"
rs.Open SQL,conn,1,1
FileType=rs("FileType")
FileSize=rs("FileSize")
FileAddress=rs("FileAddress")
rs.close
iCount=1
Set FileUp=server.createobject("ChinaASP.UpLoad") '创建文件上传对象FileUp
'以下是取得添加新闻的数据,注:由于同时上传文件所以在取得新闻数据时
'我们是用FileUp对象的方法取得数据
SoftWareId=FileUp.Form("SoftWareId")
SoftWarePicExe= FileUp.Form("SoftWarePicExe")
for each f in FileUp.Files
if f.isempty=false then
IF Clng(f.FileSize) >Clng(FileSize)*1024 Then
messageBoxone("文件大小超出限制")
End if
IF InStr(Ucase(FileType), Ucase(GetExtendName(f.fileName)))=False Then
messageBoxone("文件类型错误")
End if
SoftWarePicExeNew=GetExtendName(f.fileName)
end if
next
'加入数据
if (SoftWarePicExeNew<>"") and (SoftWarePicExeNew<>SoftWarePicExe) then
IF SoftWarePicExe<>"" Then '判断在数据库中是否有附件,有则执行下面代码
Set FSO=Server.CreateObject("Scripting.FileSystemObject") '创建FSO对象
IF FSO.fileExists(Server.MapPath(FileAddress&SoftWareId&"."&SoftWarePicExe))Then '检查文件是否存在
FSO.DeleteFile Server.MapPath(FileAddress&SoftWareId&"."&SoftWarePicExe),true '执行删除文件
Else '如果文件为空不进行处理
End IF '结束文件检查
Set FSO=nothing
End IF '结束判断
SQL = "update CySoftWare set SoftWarePicExe='"&SoftWarePicExeNew&"' "
SQL = SQL & "where SoftWareId="&SoftWareId
'Response.Write SQL
conn.execute(SQL)
end if
for each f in FileUp.Files
'IF Clng(f.FileSize) >Clng(FileMaxSize) Then
' messageBoxone("文件大小超出限制")
'End if
if f.isempty=false then
'文件上传
f.saveas Server.MapPath(FileAddress & SoftWareId & "."& SoftWarePicExeNew)
end if
next