自动采集程序

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了自动采集程序脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
复制代码 代码如下:

<%&nbsp;
  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) 
      End If 
      Set folder=Nothing 
      file=xmlhttp.ResponseBody 
      If lenb(file) > allowFileSize Then 
        getFile = "文件太大,不能保存!" 
        Exit Function 
      Else 
        Set objADOStream=Server.Createobject("ADODB.Str"&"eam") 
        objAdostream.Open() 
        objAdostream.Type=1 
        objAdostream.Write(file) 
        objAdostream.SaveToFile(Server.Mappath(uploadPath & folderName &"/" & newFilePath)) 
        objAdostream.SetEOS 
        Set objAdostream=Nothing 
        getFile= "<a href="""&uploadPath & folderName &"/" & newFilePath&""" target=""_balnk"">采集成功</a>" 
      End If 
    End If 
    Set xmlhttp=Nothing 
  End Function 
%> 
<script runat="server" language="jscript"> 
function cleanFileName(str){ 
 str = str.replace(/[^_\.a-zA-Z\d]/ig,""); 
 str = str.replace(/^[\/\.]+/,""); 
 return str; 

function getNow(n) 

  d = new Date(); 
  switch (n) 
  { 
    case "Year": 
      return d.getYear(); 
    case "Month": 
     return (d.getMonth() + 1); 
    case "Date": 
      return d.getDate(); 
  } 

</script> 
<%if request("do")="getfile" and request("file") <> "" then 
response.write(getFile(request("file"))) 
else%> 
<form id="gform" ;method="post" action="?do=getfile" style="display: inline"> 
 <input name="file" type="input" style="font-Size:12px;" size="40" value="http://blog.xiaobin.net/uploads/200512/08_093616_01.gif">  
 <input type="Submit" name="Submit" value="采集 " class="button"> 
</form> 
<%end if%>

脚本宝典总结

以上是脚本宝典为你收集整理的自动采集程序全部内容,希望文章能够帮你解决自动采集程序所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: