国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

自動采集程序

2020-07-27 13:28:47
字體:
來源:轉載
供稿:網友
最近在做一個音樂站,音樂文件嘛。。。一般是從網上收集。。so。。寫了一段采集程序。 
復制代碼 代碼如下:

<%
  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">&nbsp;
 <input type="Submit" name="Submit" value="采集 " class="button">
</form>
<%end if%>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江达县| 堆龙德庆县| 九龙城区| 普兰店市| 卢氏县| 石楼县| 贵阳市| 青田县| 清原| 北宁市| 九龙坡区| 灌阳县| 涪陵区| 建瓯市| 浦江县| 江山市| 永胜县| 深圳市| 阿巴嘎旗| 新昌县| 宁夏| 台山市| 达拉特旗| 万荣县| 宁阳县| 拜城县| 临安市| 金沙县| 阿拉尔市| 黑河市| 宜兴市| 象山县| 绥中县| 府谷县| 陕西省| 福安市| 利津县| 汉沽区| 祁东县| 安平县| 钟山县|