I'm working on a music site recently, it's a music file. . . It is usually collected from the Internet. . so. . A collection procedure was written.
The code copy is as follows:
<%
OnErrorResumeNext
ConstuploadPath="/uploads/"' file storage path
ConstallowFileExt="jpg,wma,swf,gif"'Allowed to be collected file types
'ConstallowFileSize="200"
FunctiongetFile(url)
Ifurl=""Then
ExitFunction
Else
url=Trim(url)
EndIf
'Get the file
fileExt=Lcase(Mid(url,Instrrev(url,".")+1))' file type
fileName=Lcase(Mid(url,Instrrev(url,"/")+1,Instrrev(url,".")-Instrrev(url,"/")-1))'No file type file name
newFilePath=getNow("Date")&"_"&Replace(FormatDateTime(Now(),3),":","")&"_"&cleanFileName(fileName)&"."&fileExt
ifInstr(","&Lcase(allowFileExt)&",",",","&fileExt&",")=0Then
getFile="File type not allowed"
ExitFunction
EndIf
Setxmlhttp=Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.open"get",url,false
xmlhttp.send
'Whilexmlhttp.readyState<>4
'xmlhttp.waitForResponse1000
'Wend
Ifxmlhttp.status<>200Then
getFile="Error getting file"
ExitFunction
Else
Setfolder=Server.CreateObject("Scripting.FileSystemObject")
DimfolderName
folderName=getNow("Year")&getNow("Month")' folder
Ifffolder.FolderExists(Server.MapPath(uploadPath))=FalseThen
folder.CreateFolderServer.MapPath(uploadPath)
EndIf
Ifffolder.FolderExists(Server.MapPath(uploadPath&folderName))=FalseThen
folder.CreateFolderServer.MapPath(uploadPath&folderName)