復制代碼 代碼如下:
<%
On Error Resume Next
Const uploadPath = "/uploads/" '文件存放路徑
Const allowFileExt = "jpg,wma,swf,gif" '允許被采集的文件類型
'Const allowFileSize = "200"
Function getFile(url)
If url = "" Then
Exit Function
Else
url = Trim(url)
End If
'獲取文件
fileExt = Lcase(Mid(url,Instrrev(url, ".")+1)) '文件類型
fileName = Lcase(Mid(url,Instrrev(url, "/")+1,Instrrev(url, ".")-Instrrev(url, "/")-1)) '無文件類型的文件名
newFilePath = getNow("Date") & "_" & Replace(FormatDateTime(Now(),3),":","") & "_" & cleanFileName(fileName) & "." & fileExt
if Instr(","&Lcase(allowFileExt)&",",","&fileExt&",") = 0 Then
getFile = "文件類型不允許"
Exit Function
End If
Set xmlhttp = Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
'While xmlhttp.readyState <> 4
' xmlhttp.waitForResponse 1000
'Wend
If xmlhttp.status <> 200 Then
getFile="獲取文件出錯"
Exit Function
Else
Set folder=Server.CreateObject("Scripting.FileSystemObject")
Dim folderName
folderName = getNow("Year")&getNow("Month") '文件夾
If folder.FolderExists(Server.MapPath(uploadPath))=False Then
folder.CreateFolder Server.MapPath(uploadPath)
End If
If folder.FolderExists(Server.MapPath(uploadPath & folderName))=False Then
folder.CreateFolder Server.MapPath(uploadPath & folderName)