📄 newsuploadfileok.asp
字号:
<%OPTION EXPLICIT%>
<!--#include file=chkuser.asp -->
<!--#include FILE="upload.inc"-->
<html>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK href=site.css rel=stylesheet>
<title>文章附件上传</title>
</head>
<body topmargin="0"><!--#include file=top.asp-->
<p align=center>文件上传!<hr size=1 noshadow width=300 align=center>
<p align="center"><br><br>
<%
dim upload,file,formName,formPath,iCount,newsid,smallclassid,bigclassid,filecontent,rs,sql,conn,strsql,uploadtype,upload1,i,uploadsuc
set upload=new upload_5xSoft ''建立上传对象
if upload.form("filepath")="" then ''得到上传目录
HtmEnd "请确认上传目录存在!"
set upload=nothing
response.end
else
formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
end if
newsid=upload.form("newsid")
smallclassid=upload.form("smallclassid")
bigclassid=upload.form("bigclassid")
StrSQL="DBQ="+server.mappath("data/news30000.mdb")+";DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open StrSQL
set rs=server.createobject("adodb.recordset")
sql="select * from system"
rs.open sql,conn,1,3
uploadtype=rs("uploadtype")
rs.close
set rs=nothing
iCount=1
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
upload1=split(uploadtype,",")
for i=0 to ubound(upload1)
if lcase(getFileExtName(file.fileName))=trim(upload1(i)) then
uploadsuc=true
exit for
else
uploadsuc=false
end if
next
if lcase(getFileExtName(file.fileName))="asp" or lcase(getFileExtName(file.fileName))="asa" or lcase(getFileExtName(file.fileName))="aspx" then
uploadsuc=false
end if
if uploadsuc=true then
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
if lcase(getFileExtName(file.fileName))="bmp" or lcase(getFileExtName(file.fileName))="jpg" or lcase(getFileExtName(file.fileName))="png" or lcase(getFileExtName(file.fileName))="gif" then
set rs=server.createobject("adodb.recordset")
sql="select * from news where newsid="&newsid
rs.open sql,conn,1,3
if not rs.EOF then
rs("picname")=NewsID & "-" & cstr(iCount)&"."&lcase(getFileExtName(file.fileName))
rs.update
end if
rs.close
set rs=nothing
end if
filecontent=upload.form("filecontent"&cstr(iCount)&"")
set rs=server.createobject("adodb.recordset")
sql="select * from attach where attachname='"&NewsID & "-" & cstr(iCount)&"'"
rs.open sql,conn,1,3
if not rs.EOF then
conn.execute("delete from attach where attachname='"&NewsID & "-" & cstr(iCount)&"'")
end if
rs.addnew
rs("newsid")=newsid
rs("attachcontent")=filecontent
rs("attachtype")=lcase(getFileExtName(file.fileName))
rs("attachname")=NewsID & "-" & cstr(iCount)
rs("filename")=NewsID & "-" & cstr(iCount)&"."&lcase(getFileExtName(file.fileName))
rs.update
rs.close
set rs=nothing
file.SaveAs Server.mappath(formPath& NewsID & "-" & cstr(iCount)&"."& lcase(getFileExtName(file.fileName))) ''保存文件
response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&Server.mappath(formPath)&"\"& NewsID & "-" & cstr(iCount)&"."& lcase(getFileExtName(file.fileName))&" 成功!<br>"
iCount=iCount+1
end if
else
response.write "文件格式不对<br><a href=javascript:history.go(-1)>返回重新选择文件</a><br>"
end if
set file=nothing
next
set upload=nothing ''删除此对象
if smallclassid<>"" then
response.write iCount-1&" 个文件上传结束!<br><a href=""listnews.asp?smallclassid="&smallclassid&""">继续管理其它文章</a>"
else
response.write iCount-1&" 个文件上传结束!<br><a href=""smallclass.asp?bigclassid="&bigclassid&""">继续管理其它文章</a>"
end if
sub HtmEnd(Msg)
set upload=nothing
response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">返回</a>]</body></html>"
response.end
end sub
%> </p>
</body>
</html>
<%
'获得文件的后缀名
function getFileExtName(fileName)
dim pos
pos=instrrev(filename,".")
if pos>0 then
getFileExtName=mid(fileName,pos+1)
else
getFileExtName=""
end if
end function
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -