📄 oa_save.asp
字号:
<%'''Option Explicit%>
<!--#include FILE="../inc/upfile_class.asp"-->
<!--#include file="../inc/conn.asp"-->
<%
Const UpFileType="rar|zip|wps|doc|"
dim upfile,formPath,ServerPath,FSPath,formName,FileName,oFile,upfilecount,founderr
founderr=true
upfilecount=0
set upfile=new upfile_class ''建立上传对象
upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;cer;asa;"
'upfile.AllowExt="jpg;rar;zip"
upfile.GetData (10240000) '取得上传数据,限制最大上传10M
%>
<html>
<head>
<title>文件上传</title>
<style type="text/css">
<!--
.p9{ font-size: 9pt; font-family: 宋体 }
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body leftmargin="20" topmargin="20" class="p9">
<p class="tx1"><font color="#0000FF" size="4"><%=upfile.Version%> </font></p>
<hr size=1 noshadow width=300 align=left>
<%
if upfile.isErr then '如果出错
select case upfile.isErr
case 1
Response.Write "你没有上传数据"
case 2
Response.Write "你上传的文件超出我们的限制,最大10M"
end select
else
%>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" class="p9" style="border-collapse: collapse">
<tr bgcolor="#CCCCCC">
<td height="25" valign='middle'> 本地文件 </td>
<td valign='middle'> 大小(字节) </td>
<td valign='middle'> 上传到 </td>
<td valign='middle'> 状态 </td>
</tr>
<%
FSPath=GetFilePath(Server.mappath("oa_save.asp"),"\")'取得当前文件在服务器路径
ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
for each formName in upfile.file '列出所有上传了的文件
set oFile=upfile.file(formname)
dim arrUpFileType,j
arrUpFileType=split(UpFileType,"|")
for j=0 to ubound(arrUpFileType)
if fileEXT=trim(arrUpFileType(j)) then
founderr=true
exit for
end if
next
if founderr=false then
dim ranNum,FileExt,uploadfiles,uploadfiles1,filename0,filesize0 ,fileext0
FileExt=lcase(ofile.FileExt)
randomize
ranNum=int(900*rnd)+100
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&FileExt
' FileName=upfile.form(formName)'取得文本域的值
if not FileName>"" then FileName=oFile.filename'如果没有输入新的文件名,就用原来的文件名
upfile.SaveToFile formname,FSPath&FileName ''保存文件 也可以使用AutoSave来保存,参数一样,但是会自动建立新的文件名
uploadfiles1 =uploadfiles1 &"|"& FileName
filename0=filename0 &"|"& oFile.FileName
filesize0 =filesize0&"|"& oFile.Filesize
fileext0 =fileext0&"|"& oFile.Fileext
%>
<tr>
<td height="20" valign='middle'> <%=oFile.FilePath&oFile.FileName%> </td>
<td valign='middle'> <%=oFile.filesize%> </td>
<td valign='middle'> <a href="<%=serverpath&FileName%>"><%=FileName%></a> </td>
<td valign='middle'>
<%
if upfile.iserr then
Response.Write upfile.errmessage
else
upfilecount=upfilecount+1
' uploadfiles1=split(uploadfiles,",")
Response.Write "上传成功"
' response.write("只允许上传文件格式为:rar|zip|wps|doc" )
end if
%>
</td>
</tr>
<%
set oFile=nothing
next
end if
%>
<tr>
<td colspan="3" height="25" valign='middle'> 一共上传了<%=upfileCount%>个文件</td>
</tr>
<%
'写入数据库
dim rs,sql,title,content,author,school
title=replacebadchar(trim(upfile.form("title")))
content=replacebadchar(trim(upfile.form("content")))
author=replacebadchar(trim(upfile.form("author")))
school=replacebadchar(trim(upfile.form("school")))
set rs=Server.CreateObject("ADODB.RECORDSET")
sql="Select oa_title,oa_content,oa_author,uploadfiles,filename,filecount,filesize,fileext from [oa_data]"
rs.open sql,conn,1,3
rs.addnew
rs("oa_title")=title
rs("oa_content")=content
rs("oa_author")=author
rs("uploadfiles")=uploadfiles1
rs("filename")=filename0
rs("filecount")=upfilecount
rs("filesize")=filesize0
rs("fileext")=fileext0
rs("oa_fruit")=school
rs.update
rs.close
end if
set upfile=nothing '删除此对象
%>
</table>
<p></p>
</p>
[<a href="./">返回</a>]
</body>
</html>
<%
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -