📄 post_upload.asp
字号:
<!-- #include File="inc/Upload_Class.asp" -->
<%
If Request("t")="1" Then
Upfile_Main()
Else
Main()
End If
Sub Main()
%>
<style>
BODY{
font-family:verdana,arial,helvetica;
margin:0;
}
td {
font-family:Tahoma,Verdana, Arial;
font-size:11px;
}
A:link, A:active,A:visited
{
color: #CCCCCC;
text-decoration: none;
padding-left:6px;
padding-right:6px;
}
A:hover
{
color: #FF3300;
text-decoration: none;
padding-left:6px;
padding-right:6px;
}
</style><table width="51%" border=0 cellpadding=0 cellspacing=0 >
<form name="form" method="post" action="post_upload.asp?t=1" enctype="multipart/form-data">
<tr>
<%
Dim PostRanNum
Randomize
PostRanNum = Int(900*rnd)+1000
Session("UploadCode") = Cstr(PostRanNum)
%>
<INPUT TYPE="hidden" NAME="UploadCode" value="<%=PostRanNum%>">
<TD valign=top class=tablebody2 id="upid"><input type="file" name="file1" width=200 value="" size="20" />
<input type="submit" name="Submit" value="上传"></TD>
</tr>
</form>
</table>
<p>注:支持上传图片格式:.gif .jpeg .jpg .bmp .png </p>
<%
End Sub
Sub Upfile_Main()
'-----------------------------------------------------------------------------
'提交验证
'-----------------------------------------------------------------------------
UploadFile
%>
<%
End Sub
Sub UploadFile()
Dim Upload,FormName,FilePath,ChildFilePath
Dim File,F_FileName,F_ViewName,F_Filesize,F_FileExt,F_Type
'上传目录
FilePath = CreatePath(CheckFolder)
Set Upload = New UpFile_Cls
Upload.UploadType = 0 '设置上传组件类型
Upload.UploadPath = FilePath '设置上传路径
Upload.InceptFileType = "gif,jpeg,jpg,bmp,doc,rar,zip" '设置上传文件限制
Upload.MaxSize = 20000000 '单位 KB
Upload.InceptMaxFile = 1 '每次上传文件个数上限
Upload.ChkSessionName = "UploadCode" '防止重复提交,SESSION名与提交的表单要一致。
'执行上传
Upload.SaveUpFile
If Upload.ErrCodes<>0 Then
Response.write "错误:"& Upload.Description & "[ <a href=""post_upload.asp?"">重新上传</a> ]"
Exit Sub
End If
If Upload.Count > 0 Then
For Each FormName In Upload.UploadFiles
Set File = Upload.UploadFiles(FormName)
F_FileName = FilePath & File.FileName
Response.write "<script>window.opener.document.form1.bookpic.value='"&F_FileName&"'</script>"
Response.write "<script language=javascript>"
Response.write "alert('文件上传成功!请不要修改生成的地址!');"
Response.write "window.close();"
response.write "</script>"
Set File = Nothing
Next
Else
Response.write "请正确选择要上传的文件。[ <a href=""post_upload.asp"">重新上传</a> ]"
Exit Sub
End If
Set Upload = Nothing
End Sub
'读取上传目录
Function CheckFolder()
CheckFolder = Replace(Replace("UploadFile/",Chr(0),""),".","")
'在目录后加(/)
If Right(CheckFolder,1)<>"/" Then CheckFolder=CheckFolder&"/"
End Function
'按月份自动明名上传文件夹,需要FSO组件支持。
Private Function CreatePath(PathValue)
Dim objFSO,Fsofolder,uploadpath
'以年月创建上传文件夹,格式:2003-8
uploadpath = year(now) & "-" & month(now)
If Right(PathValue,1)<>"/" Then PathValue = PathValue&"/"
On Error Resume Next
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(Server.MapPath(PathValue & uploadpath))=False Then
objFSO.CreateFolder Server.MapPath(PathValue & uploadpath)
End If
If Err.Number = 0 Then
CreatePath = PathValue & uploadpath & "/"
Else
CreatePath = PathValue
End If
Set objFSO = Nothing
End Function
%>
</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -