文件上传代码,这段上传代码都不知道是我什么时候写的了,哈哈还是也拿出来吧,
<%
dim filename,filepath,filetype,obstream,fso,fod,sql'定义变量
filepath=request.Form("filename"'取得文件路径
if len(filepath)=0 or instr(filepath,"'"<>0 then'路径的合法性
response.Redirect("firstfile.asp?info=文件不合法"
else
filename=mid(filepath,instrrev(filepath,"\"+1)'取得文件名
filetype=mid(filename,instrrev(filename,"."+1)'取得文件类型
imagepath=server.mappath("image"
if instr(filetype,"jpg"<>0 or instr(filetype,"gif"<>0 or instr(filetype,"png"<>0 then'判断是否为我们要上传的文件
set fso=server.createobject("scripting.filesystemobject"
set fod=fso.getfolder(imagepath)
for each f in fod.files
f=mid(f,instrrev(f,"\"+1)
if f=filename then'判断文件是否存在
response.Redirect("firstfile.asp?info=文件己存在"
end if
next
set fso=nothing
set obstream=server.createobject("adodb.stream"
obstream.type=1
obstream.open
obstream.loadfromfile filepath
path="image\"&filename
if obstream.size<500*1024 then
sql="select * from jimmy"
call opendb()
rs.open sql,cnn,1,3
rs.addnew
rs("image_path"=path
rs.update
call closedb()
obstream.savetofile server.mappath(path)'上传文件
response.Redirect("firstfile.asp?info=上传文件成功"
end if
obstream.close
set obstream=nothing
else
response.Redirect("firstfile.asp?info=文件不合法,必须是图片文件jpg,gif,png,"
end if
end if
%>