<!--#include file="upload_5xsoft.inc"-->
<%
'无组件上传文件调用
'Form的enctype必须为"multipart/form-data",Method必须为post
Dim iCount,FormPath,Upload,ExtendName
Set Upload=New upload_5xSoft
FormPath="upload/"
iCount=0
ExtendName="jpg,bmp,gif"
For Each formName in Upload.file
iCount=iCount+1
Set file=Upload.file(formName)
If file.FileSize>0 then
NewName=SetName()&"."&GetExtendName(file.FileName)
OpenMode=GetExtendName(file.FileName) ''''''''''''''''取得文件的扩展名
'限制图片上传类型
GetExtendMatch ExtendName,OpenMode
'新建文件夹
SetFolder(FormPath)
'保存图片
file.SaveAs Server.mappath(FormPath&SetFolder(FormPath)&"/"&NewName)
Select Case iCount
case 1
File1 = FormPath&SetFolder(FormPath)&"/"&NewName
case 2
File2 = FormPath&SetFolder(FormPath)&"/"&NewName
case 3
File3 = FormPath&SetFolder(FormPath)&"/"&NewName
End Select
Else
If file.FileName <> "" Then
Dispmess( "please" )
Response.end
End If
End If
Set file=Nothing
Next
'※※※※※※※※※※※※※※※※※※
'允许上传的文件
'参数ExtendName,扩展名集,扩展名用“,”隔开,并且用小写;
'参数OpenMode,验证的扩展名
'※※※※※※※※※※※※※※※※※※
Sub GetExtendMatch(ExtendName,OpenMode)
Dim Judge,OpenMode1
Judge=False
OpenMode1=LCase(OpenMode)
ExtendArry=Split(ExtendName,",")
For Each OpenMode1 In ExtendArry
Judge=True
Next
If Judge=False Then
Response.Write("<script language=javascript>alert('上传文件类型不正确')</script>")
Response.Write("<script language=javascript>history.go(-1)</script>")
Response.End
End If
End Sub
'※※※※※※※※※※※※※※※※※※
'新建文件夹
'※※※※※※※※※※※※※※※※※※
Function SetFolder(FormPath)
Dim DateFolder,Dbpath,objFs
DateFolder=cstr(year(date()))+cstr(month(date()))+cstr(day(date()))
Dbpath = server.mappath(FormPath&DateFolder)
Set objFs = Server.CreateObject("Scripting.FileSystemObject")
If Not objFs.FolderExists(Dbpath) Then
objFs.CreateFolder Dbpath
End If
Set objFs = Nothing
SetFolder=DateFolder
End Function
'※※※※※※※※※※※※※※※※※※
'取得扩展名
'※※※※※※※※※※※※※※※※※※
Function GetExtendName(FileName)
GetExtendName=Mid(FileName,InStrRev(FileName, ".")+1)
End Function
'※※※※※※※※※※※※※※※※※※
'生成文件名称
'※※※※※※※※※※※※※※※※※※
Function SetName()
Dim IP,NowTime,FileRename
IP= Cstr(Request.ServerVariables("REMOTE_ADDR"))
NowTime=now()
Randomize
FileRename=IP
FileRename=IP+Cstr(Year(NowTime))
FileRename=FileRename+Cstr(Month(NowTime))
FileRename=FileRename+Cstr(Day(NowTime))
FileRename=FileRename+Cstr(Hour(NowTime))
FileRename=FileRename+Cstr(Minute(NowTime))
FileRename=FileRename+Cstr(Second(NowTime))
FileRename=FileRename+Cstr((10000 * Rnd) + 1)
FileRename=Replace(FileRename,".","")
SetName=FileRename
End Function
%>