最近在做一个音乐站,音乐文件嘛。。。一般是从网上收集。。so。。写了一段采集程序。
复制代码代码如下:
<%
OnErrorResumeNext
ConstuploadPath="/uploads/"'文件存放路径
ConstallowFileExt="jpg,wma,swf,gif"'允许被采集的文件类型
'ConstallowFileSize="200"
FunctiongetFile(url)
Ifurl=""Then
ExitFunction
Else
url=Trim(url)
EndIf
'获取文件
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
ifInstr(","&Lcase(allowFileExt)&",",","&fileExt&",")=0Then
getFile="文件类型不允许"
ExitFunction
EndIf
Setxmlhttp=Server.CreateObject("Microsoft.XMLHTTP")
xmlhttp.open"get",url,false
xmlhttp.send
'Whilexmlhttp.readyState<>4
'xmlhttp.waitForResponse1000
'Wend
Ifxmlhttp.status<>200Then
getFile="获取文件出错"
ExitFunction
Else
Setfolder=Server.CreateObject("Scripting.FileSystemObject")
DimfolderName
folderName=getNow("Year")&getNow("Month")'文件夹
Iffolder.FolderExists(Server.MapPath(uploadPath))=FalseThen
folder.CreateFolderServer.MapPath(uploadPath)
EndIf
Iffolder.FolderExists(Server.MapPath(uploadPath&folderName))=FalseThen
folder.CreateFolderServer.MapPath(uploadPath&folderName)