自動(dòng)采集程序
更新時(shí)間:2006年10月25日 00:00:00 作者:
復(fù)制代碼 代碼如下:
<%
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)) '無(wú)文件類型的文件名
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="獲取文件出錯(cuò)"
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%>
相關(guān)文章
asp實(shí)現(xiàn)的7xi音樂(lè)網(wǎng)的采集源代碼
asp實(shí)現(xiàn)的7xi音樂(lè)網(wǎng)的采集源代碼...2007-03-03利用MSXML2.XmlHttp和Adodb.Stream采集圖片
asp下經(jīng)常用來(lái)采集的兩個(gè)組件結(jié)合使用例子2008-05-05使用xmlHttp結(jié)合ASP實(shí)現(xiàn)網(wǎng)頁(yè)的異步調(diào)用
使用xmlHttp結(jié)合ASP實(shí)現(xiàn)網(wǎng)頁(yè)的異步調(diào)用...2006-06-06獨(dú)孤劍寫的馬克斯迅雷片庫(kù)采集插件1.4 官方最新版提供下載了
非常不錯(cuò)的采集迅雷插件,經(jīng)本人測(cè)試非常不錯(cuò),而且作者很熱心,是個(gè)好人,希望大家支持下,不要拿去賣了。2008-01-01發(fā)一個(gè)采集(小偷)用的類,ASP+緩存實(shí)現(xiàn)
發(fā)一個(gè)采集(小偷)用的類,ASP+緩存實(shí)現(xiàn)...2007-02-02圖片自動(dòng)保存到本地并利用aspjpeg為圖片加水印
圖片自動(dòng)保存到本地并利用aspjpeg為圖片加水印...2006-07-07