The collection program can directly or indirectly obtain data according to the rules. Therefore, many people will write the collection program themselves for convenience. So how should they write the collection program? Below is the example code of the automatic collection program compiled by the editor of Foxin for everyone.
The code copy is as follows:<%
On Error Resume Next
Const uploadPath = "/uploads/" 'File storage path
Const allowFileExt = "jpg,wma,swf,gif" 'Allowed to be collected file type
'Const allowFileSize = "200"
Function getFile(url)
If url = "" Then
Exit Function
Else
url = Trim(url)
End If
'Get the file
fileExt = Lcase(Mid(url,Instrrev(url, ".")+1)) 'File Type
fileName = Lcase(Mid(url,Instrrev(url, "/")+1,Instrrev(url, ".")-Instrrev(url, "/")-1)) 'File name without file type
newFilePath = getNow("Date") & "_" & Replace(FormatDateTime(Now(),3),":","") & "_" & cleanFileName(fileName) & "." & fileExt
if Instr(","&Lcase(allowFileExt)&",",",","&fileExt&",") = 0 Then
getFile = "File type not allowed"
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="Error getting file"
Exit Function
Else
Set folder=Server.CreateObject("Scripting.FileSystemObject")
Dim folderName
folderName = getNow("Year")&getNow("Month") ' folder
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 = "The file is too big to save!"
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"">Collection successfully</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="Collection " class="button">
</form>
<%end if%>
The above is an example code for the automatic collection program. If you want to know more deeply, you can enter the wrong new technology channel to learn about it.