コレクションプログラムは、ルールに従って直接的または間接的にデータを取得できます。したがって、多くの人々が利便性のためにコレクションプログラムを自分で書きます。では、彼らはどのようにコレクションプログラムを書くべきですか?以下は、Foxinの編集者がすべての人に編集した自動収集プログラムの例です。
コードコピーは次のとおりです。<%
エラーの再開時に次に再開します
const uploadpath = "/uploads/" 'ファイルストレージパス
const approwfileext = "jpg、wma、swf、gif" 'ファイルタイプを収集することを許可
'const avoldfilesize = "200"
function getFile(url)
url = "" thenの場合
出口機能
それ以外
url = trim(url)
ifを終了します
'ファイルを取得します
fileext = lcase(mid(url、instrrev(url、 "。")+1) 'ファイルタイプ
filename = lcase(mid(url、instrrev(url、 "/")+1、instrrev(url、 "。") - instrrev(url、 "/") - 1)) 'ファイル型なしのファイル名
newFilePath = getNow( "date")& "_"&fact(formatdatetime(now()、3)、 ":"、 "")& "_"&cleanfileName(filename)& "。"。 " &fileext
If strust( "、"&lcase(approwfileext)& "、"、 "、"、 "&fileext&"、 ")= 0
getFile = "ファイルタイプは許可されていません"
出口機能
ifを終了します
xmlhttp = server.createObject( "microsoft.xmlhttp")を設定します
xmlhttp.open "get"、url、false
xmlhttp.send
'while xmlhttp.ReadyState <> 4
'xmlhttp.waitforresponse 1000
'ウェンド
xmlhttp.status <> 200の場合
getFile = "ファイルの取得エラー"
出口機能
それ以外
set folder = server.createObject( "Scripting.filesystemObject")
DIM FOLDRNAME
foldername = getNow( "year")&getNow( "month") 'フォルダー
folder.folderexists(server.mappath(uploadpath))= falseの場合
folder.createfolder server.mappath(uploadpath)
ifを終了します
folder.folderexists(server.mappath(uploadpath&foldername))= falseの場合
folder.createfolder server.mappath(uploadpath&foldername)
ifを終了します
SET FOLDER = Nothing
file = xmlhttp.responsebody
lenb(file)> akpoldfilesizeの場合
getFile = "ファイルが大きすぎて保存できません!"
出口機能
それ以外
objadostream = server.createobject( "adodb.str"& "eam")を設定します
objadostream.open()
objadostream.type = 1
objadostream.write(file)
objadostream.savetofile(server.mappath(uploadpath&foldername& "/"&newfilepath)))
objadostream.seteos
objadostream = Nothingを設定します
getFile = "<a href =" ""&uploadpath&foldername& "/"&newfilepath& "" "" "" _ balnk "">コレクション</a> "
ifを終了します
ifを終了します
xmlhttp = Nothingを設定します
エンド関数
%>
<スクリプトrunat = "server"言語= "jscript">
関数CleanFileName(str){
str = str.replace(/[^_/。a-za-z/d]/ig、 "");
str = str.replace(/^ [////.]+"");
strを返します。
}
関数GetNow(n)
{
d = new date();
スイッチ(n)
{
ケース「年」:
d.getyearを返します();
ケース「月」:
return(d.getmonth() + 1);
ケース「日付」:
d.getDateを返します();
}
}
</script>
<%if request( "do")= "getFile"とrequest( "file")<> "" then
respons.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">
<入力型= "submit" name = "" submit "value =" collection "class =" button ">
</form>
<%end if>
上記は、自動収集プログラムの例コードです。もっと深く知りたい場合は、間違った新しいテクノロジーチャネルを入力して学習できます。