手机
当前位置:查字典教程网 >编程开发 >ASP教程 >自动采集程序
自动采集程序
摘要:最近在做一个音乐站,音乐文件嘛。。。一般是从网上收集。。so。。写了一段采集程序。复制代码代码如下:allowFileSizeThenget...

最近在做一个音乐站,音乐文件嘛。。。一般是从网上收集。。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)

EndIf

Setfolder=Nothing

file=xmlhttp.ResponseBody

Iflenb(file)>allowFileSizeThen

getFile="文件太大,不能保存!"

ExitFunction

Else

SetobjAdostream=Server.Createobject("ADODB.Str"&"eam")

objAdostream.Open()

objAdostream.Type=1

objAdostream.Write(file)

objAdostream.SaveToFile(Server.Mappath(uploadPath&folderName&"/"&newFilePath))

objAdostream.SetEOS

SetobjAdostream=Nothing

getFile="<ahref="""&uploadPath&folderName&"/"&newFilePath&"""target=""_balnk"">采集成功</a>"

EndIf

EndIf

Setxmlhttp=Nothing

EndFunction

%>

<scriptrunat="server"language="jscript">

functioncleanFileName(str){

str=str.replace(/[^_.a-zA-Zd]/ig,"");

str=str.replace(/^[/.]+/,"");

returnstr;

}

functiongetNow(n)

{

d=newDate();

switch(n)

{

case"Year":

returnd.getYear();

case"Month":

return(d.getMonth()+1);

case"Date":

returnd.getDate();

}

}

</script>

<%ifrequest("do")="getfile"andrequest("file")<>""then

response.write(getFile(request("file")))

else%>

<formid="gform"method="post"action="?do=getfile"style="display:inline">

<inputname="file"type="input"style="font-size:12px;"size="40"value="http://blog.xiaobin.net/uploads/200512/08_093616_01.gif">

<inputtype="Submit"name="Submit"value="采集"class="button">

</form>

<%endif%>

【自动采集程序】相关文章:

tsys _rss程序

ASP:页面输出太多会严重影响web程序的性能

浅谈自动采集程序及入库

ASP 程序实现自动升级功能

pjblog中清空引用的小程序

编写通用的asp防注入程序

自动采集程序

一段采集程序代码

ASP应用之模板采用

用asp自动解析网页中的图片地址

精品推荐
分类导航