📄 oa_upfile1.asp
字号:
<%'Option Explicit%>
<!--#include FILE="../inc/upfile_class.asp"-->
<!--#include file="../inc/conn.asp"-->
<%
Server.ScriptTimeOut = 1800
' 参数变量
Dim sType, sStyleName
' 设置变量
Dim sAllowExt, nAllowSize, sUploadDir, nUploadObject, nAutoDir, sBaseUrl, sContentPath
' 接口变量
Dim sFileExt, sOriginalFileName, sSaveFileName, sPathFileName, nFileNum
sAllowExt="rar|zip|wps|doc|"
dim upfile,formPath,ServerPath,FSPath,formName,FileName,oFile,upfilecount,founderr,SavePath
dim school
founderr=false
upfilecount=0
dim noupfilecount
NoUpfilecount=0
set upfile=new upfile_class ''建立上传对象
'upfile.NoAllowExt="asp;exe;htm;html;aspx;cs;vb;js;cer;asa;"
upfile.AllowExt="rar;zip;doc;wps;"
upfile.GetData (10240000) '取得上传数据,限制最大上传10M
SavePath = "/oa_files/" '存放上传文件的目录
'if right(SavePath,1)<>"/" then SavePath=SavePath&"/" '在目录后加(/)
dim rs,sql,title,content,author
title=replacebadchar(trim(upfile.form("title")))
content=replacebadchar(trim(upfile.form("content")))
author=replacebadchar(trim(upfile.form("author")))
school=replacebadchar(trim(upfile.form("school")))
if title="" or author="" or content="" then
founderr=true
%>
<script>alert('公文信息没有填写完整!');history.back();</script>
<% end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>公文附件上传信息</title>
</head>
<body>
<%
call Dupfile_Class()
%>
</body>
</html>
<%
function GetFilePath(FullPath,str)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, str))
Else
GetFilePath = ""
End If
End function
' 无组上传类
Sub Dupfile_Class()
On Error Resume Next
Dim upfile, oFile
' 建立上传对象
Set upfile = New upfile_class
' 取得上传数据,限制最大上传
upfile.GetData(nAllowSize*1024)
If upfile.Err > 0 Then
Select Case upfile.Err
Case 1
Call OutScript("parent.UploadError('请选择有效的上传文件!')")
Case 2
Call OutScript("parent.UploadError('你上传的文件总大小超出了最大限制(" & nAllowSize & "KB)!')")
End Select
Response.End
End If
FSPath=GetFilePath(Server.mappath("..\index.asp"),"\")'取得当前文件在服务器路径
ServerPath=GetFilePath(Request.ServerVariables("HTTP_REFERER"),"/")'取得在网站上的位置
for each formName in upfile.file '列出所有上传了的文件
set oFile=upfile.file(formname)
' Set oFile = upfile.File("uploadfile")
sFileExt = LCase(oFile.FileExt)
Call CheckValidExt(sFileExt)
sOriginalFileName = oFile.FileName
sSaveFileName = GetRndFileName(sFileExt)
oFile.SaveToFile Server.Mappath(sSaveFileName)
' upfile.SaveToFile(sSaveFileName) ''保存文件 也可以使用AutoSave来保存,参数一样,但是会自动建立新的文件名
next
Set oFile = Nothing
Set upfile = Nothing
End Sub
' 取随机文件名
Function GetRndFileName(sExt)
Dim sRnd
Randomize
sRnd = Int(900 * Rnd) + 100
GetRndFileName = year(now) & month(now) & day(now) & hour(now) & minute(now) & second(now) & sRnd & "." & sExt
End Function
' 输出客户端脚本
Sub OutScript(str)
Response.Write "<script language=javascript>" & str & ";history.back()</script>"
End Sub
Sub OutScriptNoBack(str)
Response.Write "<script language=javascript>" & str & "</script>"
End Sub
' 检测扩展名的有效性
Sub CheckValidExt(sExt)
Dim b, i, aExt
b = False
aExt = Split(sAllowExt, "|")
For i = 0 To UBound(aExt)
If LCase(aExt(i)) = sExt Then
b = True
Exit For
End If
Next
If b = False Then
OutScript("parent.UploadError('提示:\n\n请选择一个有效的文件,\n支持的格式有("+sAllowExt+")!')")
Response.End
End If
End Sub
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -