objCn.close
set objrst=nothing
set objcn = nothing
%>
<!--#include file="upload.asp"-->
3)显示图片文件:showpic.asp
----------------------------------------
<%
set objCn = server.createobject("adodb.connection")
set objRst = server.createobject("adodb.recordset")
objCn.Open "upload"
objrst.Open "select what from pic where id=" & request("id"), objcn
if not objrst.eof then
response.binarywrite objrst("what")
end if
objrst.close
objCn.close
set objrst=nothing
set objcn = nothing
%>
<body bgcolor="#FFFFFF" text="#000000">
<%
'因为图片是以更新的形式进行上传,所以首先检测指定记录号的记录是否存在
id1=request("id1") '取出上页传来的ID1值(用于确定操作的记录号)
session("id1")=id1 '把ID1值存入Session,下一页面将要使用
sql2="select * from tupian where id="&id1&""
set rs1=conn.execute(sql2)
if rs1.eof then '若记录不存在,则先建立它
sql1="insert into tupian(id) values("&id1&")"
conn.execute(sql1)
end if
rs1.close '关闭数据集
set rs1=nothing
saveupload.asp
___________________
<!--#include FILE="upload.asp"-->
<html>
<head>
<title>文件上传</title>
</head>
<body topmargin="0" leftmargin="0" bgcolor=#E4E4E4>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td valign=top height=40>
<%
Server.ScriptTimeOut=999999
'定义变量
dim Forumupload,ranNum
dim formName,formPath,filename,file_name,fileExt,Filesize,F_Type
dim rename,DownloadID
call upload_0()
'===========================无组件上传============================
sub upload_0()
dim upload,file
set upload=new UpFile_Class ''建立上传对象
'***************************************************
'***************此处写上不同的文件取值**************
'***************************************************
upload.GetDate (204800) '取得上传数据,204800=200K
if upload.err > 0 then
select case upload.err
case 1
Response.Write "请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
case 2
Response.Write "文件大小超过了200K的限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
end select
exit sub
else
formPath=upload.form("filepath")
'在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
fileExt=lcase(file.FileExt)
'判断文件类型
if lcase(fileEXT)="asp" and lcase(fileEXT)="asa" and lcase(fileEXT)="aspx" then
CheckFileExt(fileEXT)=false
end if
if CheckFileExt(fileEXT)=false then
response.write "文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
response.end
end if
'***************************************************
'***********此处不同的网站ranNum取值不同************
'***************************************************
'付值变量
if session("usid")="" then
response.write "非法用户!不能上传!"
response.end
else
ranNum=session("usid")
end if
ranNum=int(ranNum)+100000
ranNum=cstr(ranNum)&"_"
F_Type=CheckFiletype(fileEXT)
file_name=ranNum&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)
filename=file_name&"."&fileExt
rename=filename&"|"
filename=formPath&filename
Filesize=file.FileSize
'记录文件
if Filesize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveToFile Server.mappath(FileName) ''执行上传文件
call checksave() '记录文件
end if
set file=nothing
next
end if
set upload=nothing
response.write "文件上传成功![ <a href=# onclick=history.go(-1)>继续上传</a> ]"
end sub
Private sub checksave()
'插入上传表并获得ID
end sub
'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload
Forumupload=split("gif|jpg|jpeg","|")
for i=0 to ubound(Forumupload)
if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
CheckFileExt=true
exit Function
else
CheckFileExt=false
end if
next
End Function
%>
</td></tr>
</table>
</body>
</html>
saveupload.asp
___________________
<!--#include FILE="upload.asp"-->
<html>
<head>
<title>文件上传</title>
</head>
<body topmargin="0" leftmargin="0" bgcolor=#E4E4E4>
<table width="100%" border=0 cellspacing=0 cellpadding=0>
<tr><td valign=top height=40>
<%
Server.ScriptTimeOut=999999
'定义变量
dim Forumupload,ranNum
dim formName,formPath,filename,file_name,fileExt,Filesize,F_Type
dim rename,DownloadID
call upload_0()
'===========================无组件上传============================
sub upload_0()
dim upload,file
set upload=new UpFile_Class ''建立上传对象
'***************************************************
'***************此处写上不同的文件取值**************
'***************************************************
upload.GetDate (204800) '取得上传数据,204800=200K
if upload.err > 0 then
select case upload.err
case 1
Response.Write "请先选择你要上传的文件 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
case 2
Response.Write "文件大小超过了200K的限制 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
end select
exit sub
else
formPath=upload.form("filepath")
'在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
fileExt=lcase(file.FileExt)
'判断文件类型
if lcase(fileEXT)="asp" and lcase(fileEXT)="asa" and lcase(fileEXT)="aspx" then
CheckFileExt(fileEXT)=false
end if
if CheckFileExt(fileEXT)=false then
response.write "文件格式不正确 [ <a href=# onclick=history.go(-1)>重新上传</a> ]"
response.end
end if
'***************************************************
'***********此处不同的网站ranNum取值不同************
'***************************************************
'付值变量
if session("usid")="" then
response.write "非法用户!不能上传!"
response.end
else
ranNum=session("usid")
end if
ranNum=int(ranNum)+100000
ranNum=cstr(ranNum)&"_"
F_Type=CheckFiletype(fileEXT)
file_name=ranNum&year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)
filename=file_name&"."&fileExt
rename=filename&"|"
filename=formPath&filename
Filesize=file.FileSize
'记录文件
if Filesize>0 then '如果 FileSize > 0 说明有文件数据
file.SaveToFile Server.mappath(FileName) ''执行上传文件
call checksave() '记录文件
end if
set file=nothing
next
end if
set upload=nothing
response.write "文件上传成功![ <a href=# onclick=history.go(-1)>继续上传</a> ]"
end sub
Private sub checksave()
'插入上传表并获得ID
end sub
'判断文件类型是否合格
Private Function CheckFileExt (fileEXT)
dim Forumupload
Forumupload=split("gif|jpg|jpeg","|")
for i=0 to ubound(Forumupload)
if lcase(fileEXT)=lcase(trim(Forumupload(i))) then
CheckFileExt=true
exit Function
else
CheckFileExt=false
end if
next
End Function
%>
</td></tr>
</table>
</body>
</html>