📄 upload.asp
字号:
<!-- #Include File="../../../Include/Config.asp" -->
<!--#include file="../../../Include/Cls_Upfile.asp"-->
<%
'Cl.GetWeb_Setting()
Server.ScriptTimeOut = 999999
' 参数变量
Dim sType, sTrSetting, ComeURL, today_num
Dim sChannelID, IsTrueUpfiles
Dim sStyleName, sLanguage
'频道ID,允许上传权限
' 设置变量
Dim sAllowExt, nAllowSize, sIsReName, sUploadDir, sPreviewpath, nUploadObject, nAutoDir, sBaseUrl, sContentPath
' 接口变量
Dim sFileExt, oFileSize, sOriginalFileName, sSaveFileName, sPathFileName, nFileNum
dim strJs
Dim Upload,FormName,FilePath,ChildFilePath
Dim File,F_FileName,F_ViewName,F_Filesize,F_FileExt,F_Type
Dim DrawInfo
Dim sTObj
Call InitUpload() ' 初始化上传变量
Dim sAction
sAction = UCase(Trim(Request.QueryString("action")))
Select Case sAction
Case "REMOTE"
Call DoRemote() ' 远程自动获取
Case "SAVE"
Call ShowForm() ' 显示上传表单
Call DoSave() ' 存文件
Case Else
Call ShowForm() ' 显示上传表单
End Select
Sub ShowForm()
%>
<HTML>
<HEAD>
<TITLE>文件上传</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
body, a, table, div, span, td, th, input, select{font:9pt;font-family: "宋体", Verdana, Arial, Helvetica, sans-serif;}
body {padding:0px;margin:0px}
</style>
<script language="JavaScript" src="../dialog/dialog.js"></script>
</head>
<body bgcolor=menu>
<form action="?action=save&cid=<%=sChannelID%>&type=<%=sType%>&style=<%=sStyleName%>&TObj=<%=sTObj%>" method=post name=myform enctype="multipart/form-data">
<input type=file name=uploadfile size=1 style="width:100%" onChange="originalfile.value=this.value;SelectOnchange(this.value);">
<input type=hidden name=originalfile value="">
</form>
<script language="JavaScript" type="text/javascript">
var sAllowExt = "<%=sAllowExt%>";
// 检测上传表单
function CheckUploadForm() {
if (!IsExt(document.myform.uploadfile.value,sAllowExt)){
parent.UploadError("提示:\n\n请选择一个有效的文件,\n支持的格式有("+sAllowExt+")!");
return false;
}
return true
}
// 提交事件加入检测表单
var oForm = document.myform ;
oForm.attachEvent("onsubmit", CheckUploadForm) ;
if (! oForm.submitUpload) oForm.submitUpload = new Array() ;
oForm.submitUpload[oForm.submitUpload.length] = CheckUploadForm ;
if (! oForm.originalSubmit) {
oForm.originalSubmit = oForm.submit ;
oForm.submit = function() {
if (this.submitUpload) {
for (var i = 0 ; i < this.submitUpload.length ; i++) {
this.submitUpload[i]() ;
}
}
this.originalSubmit() ;
}
}
// 上传表单已装入完成
try {
parent.UploadLoaded();
}
catch(e){
}
function SelectOnchange(sfile){
var sType = "<%=sType%>";
if ((IsExt(sfile,'gif|bmp|jpg|png')) && (sType=="IMAGE")){
parent.doPreview();
}
}
</script>
</body>
</html>
<%
End Sub
' 保存操作
Sub DoSave()
ComeUrl=Request.ServerVariables("HTTP_REFERER")
if ComeUrl="" then ComeUrl="javascript:history.go(-1)"
if not Cls.Post_Chk then
Call OutScript("alert('您从外部提交信息,操作已被禁止。');window.close();")
Response.End
end if
'检测是否为后台管理员
If Login_Mode ="" Then
If Cls.Session_Get(Cls.Web_Cookies&"_Admin")="Admin" Then
Login_Username = Cls.Session_Get(Cls.Web_Cookies&"_Admins")
Login_Mode = "admin" '管理员的权限
End If
End If
strSetting=Cls.Web_UploadType
if strSetting(0)=999 then
Call OutScript("alert('系统未开放文件上传功能。');window.close();")
Response.End
end if
if Up_Today_Num()=false then
Call OutScript("alert('Error:您还没有登陆 或者 您今天已上传"&Today_num&"个文件,每天只能上传"&UserGroup_Config(18)&"个文件。');window.close();")
Response.End
end if
If UserGroup_Config(8)=0 then
Call OutScript("alert('此用户组上传功能已禁用!');window.close();")
Response.End
end if
if sChannelID<0 or sChannelID>999 then
Call OutScript("alert('本频道上传功能已禁用!');window.close();")
Response.End
end if
Set Upload = New UpFile_Cls
InitUpLoad_Cls
Upload.SaveUpFile
If Upload.ErrCodes<>0 Then
Call Cls.Out_Msg("错误:"& Upload.Description ,"javascript:window.Close()")
Response.End
End If
strJs=""
On Error Resume Next
If Upload.Count > 0 Then
For Each FormName In Upload.UploadFiles
Set File = Upload.UploadFiles(FormName)
sSaveFileName = File.FileName
F_FileName = sUploadDir & sSaveFileName
sPathFileName = sContentPath & sSaveFileName
'创建预览及水印图片
If Upload.PreviewType<>999 and File.FileType=1 then
F_Viewname = sPreviewpath & "pre" & Replace(File.FileName,File.FileExt,"") & "jpg"
Upload.CreateView F_FileName,F_Viewname,File.FileExt
End If
strJs=strJs&"parent.UploadSaved('" & Replace(sPathFileName,Cls.Web_Dir&Cls.Web_Upload,Cls.Web_RealURL&Cls.Web_Dir&Cls.Web_Upload) & "');var obj=parent.dialogArguments.dialogArguments;if (!obj) obj=parent.dialogArguments;try{obj.addUploadFile('" & File.OldFileName & "', '" & sSaveFileName & "', '" & Replace(sPathFileName,Cls.Web_Dir&Cls.Web_Upload,Cls.Web_RealURL&Cls.Web_Dir&Cls.Web_Upload)&"');"'} catch(e){};"
if Lcase(left(F_FileName,Len(Cls.Web_Dir & Cls.Web_Upload)))=Lcase(Cls.Web_Dir & Cls.Web_Upload) then
sPathFileName="{$download_dir}" & mid(F_FileName,Len(Cls.Web_Dir & Cls.Web_Upload)+1)
elseif Lcase(left(F_FileName,Len(Cls.Web_Upload)))=Lcase(Cls.Web_Upload) then
sPathFileName="{$upload_dir}" & mid(F_FileName,Len(Cls.Web_Upload)+1)
elseif left(sPathFileName,1)="/" then
sPathFileName="{$web_dir}" & mid(sPathFileName,2)
else
sPathFileName=Trim(sPathFileName)
end if
strJs=strJs & "obj.AddUploadFiles('"&sTObj&"','" & sPathFileName & "','" & sSaveFileName & "');} catch(e){};"
'保存数据
Call Cls.exec("insert into DB_Upload(UserName,UserIP,UpFileName,UpFileType,UpFileUrl,UpFileSize,UpFileTime) values('"&login_username&"','"&Cls.ip_sys(0)&"','"&File.FileName&"','"&File.FileExt&"','"&sPathFileName&"','"&Cls.GetSize(File.FileSize,"b")&"','"&Cls.now_time&"')",0)
Set File = Nothing
Next
Call OutScript(strJs)
Else
Call OutScript("alert('请正确选择要上传的文件。');window.close();")
Response.End
End If
Set Upload = Nothing
End Sub
' 自动获取远程文件
Sub DoRemote()
Dim sContent, i
For i = 1 To Request.Form("Editor_UploadText").Count
sContent = sContent & Request.Form("Editor_UploadText")(i)
Next
If sAllowExt <> "" Then
sContent = ReplaceRemoteUrl(sContent, sAllowExt)
End If
Response.Write "<HTML><HEAD><TITLE>远程上传</TITLE><meta http-equiv='Content-Type' content='text/html; charset=gb2312'></head><body>" & _
"<input type=hidden id=UploadText value=""" & inHTML(sContent) & """>" & _
"</body></html>"
Call OutScriptNoBack("parent.setHTML(UploadText.value);try{parent.addUploadFile('" & sOriginalFileName & "', '" & sSaveFileName & "', '" & sPathFileName & "');} catch(e){} parent.remoteUploadOK();")
End Sub
' 输出客户端脚本
Sub OutScript(str)
Response.Write "<script type=""text/javascript"">" & str & ";history.back()</script>"
End Sub
Sub OutScriptNoBack(str)
Response.Write "<script type=""text/javascript"">" & str & "</script>"
End Sub
' 初始化上传限制数据
Sub InitUpload()
sType = UCase(Trim(Cls.Code_Query("type")))
sTObj = Trim(Cls.Code_Query("TObj"))
sChannelID = Trim(Cls.Code_Query("cid"))
sStyleName = Trim(Request.QueryString("style"))
sLanguage = Trim(Request.QueryString("language"))
if Not IsNumeric(sChannelID) or sChannelID="" then
OutScript("parent.UploadError('错误,请通过页面上的链接进行操作!')")
Exit Sub
end if
Call Cls.Channel_Initialize(sChannelID)
sUploadDir = Cls.ChannelUploadDir '上传目录
nAutoDir = Cls.Get_ChannelSetup(Cls.ChannelSetup,16) '自动分类 0不使用,1按年,2年-月,3年-月-日
sPreviewpath = Replace(Cls.Web_Dir &Cls.Web_Upload &"/PreviewImage/" & sUploadDir & "/","//","/")
sUploadDir = Replace(Cls.Web_Dir &Cls.Web_Upload & "/" & sUploadDir & "/","//","/")
if nAutoDir=1 then sUploadDir = CreatePath(sUploadDir)
if nAutoDir=1 then sPreviewpath = CreatePath(sPreviewpath) '按年月分类目录
sContentPath = sUploadDir
'Cl.RelativePath2RootPath(sUploadDir)
'if sTrSetting(3)="1" then
'sContentPath = Cl.RootPath2DomainPath(sContentPath)
'end if
Select Case sType
Case "FILE"
sAllowExt = Cls.ChannelUpFileType(3)
Case "MEDIA"
sAllowExt = Cls.ChannelUpFileType(2)
Case "FLASH"
sAllowExt = Cls.ChannelUpFileType(1)
Case Else
sAllowExt = Cls.ChannelUpFileType(0)
End Select
nAllowSize = Cls.ChannelUpMax
sIsReName = Cls.Get_ChannelSetup(Cls.ChannelSetup,15) '是否重命名
' 任何情况下都不允许上传asp脚本文件
sAllowExt = Replace(UCase(sAllowExt), "ASP", "")
End Sub
'================================================
'作 用:替换字符串中的远程文件为本地文件并保存远程文件
'参 数:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -