<!-- #include file="../conn.asp" -->
<!-- #include file="admin.asp" -->
<!--#include file="upload.inc"-->
<%Call Head()%>

<%call saycardd("批量地址采集图片")
dim picsy,picsize,formatpic
			set rs=server.CreateObject("adodb.recordset")
			sql="select formatpic,picsize,picsy from twapp"
			rs.open sql,conn,1,1
formatpic=rs("formatpic")
picsize=rs("picsize")
picsy=rs("picsy")
rs.close
set rs=nothing
Server.ScriptTimeOut=9999999
Function IsFile(url) 
Dim xmlhttp : Set xmlhttp = Server.CreateObject("MSXML2.XMLHTTP") 
xmlhttp.Open "GET",url,false 
xmlhttp.send 
If xmlhttp.readyState=4 Then 
If xmlhttp.status=200 Then 
IsFile = true 
Else 
IsFile = false 
End If 
End If 
End Function

'==================================================
'过程名：SaveRemoteFile
'作  用：保存远程的文件到本地
'参  数：LocalFileName ------ 本地文件名
'参  数：RemoteFileUrl ------ 远程文件URL
'参  数：Referer ------ 远程调用文件（对付防采集的，用内容页地址，没有防的留空）
'==================================================
Function SaveRemoteFile(LocalFileName,RemoteFileUrl,Referer)
    SaveRemoteFile=True
	dim Ads,Retrieval,GetRemoteData
	Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
	With Retrieval
		.Open "Get", RemoteFileUrl, False, "", ""
		if Referer<>"" then .setRequestHeader "Referer",Referer
		On Error Resume Next
		if Err <> 0 then
			Err.Clear
			SaveRemoteFile=False
			Exit Function
		end if
		.Send
        If .Readystate<>4 then
            SaveRemoteFile=False
            Exit Function
        End If
		GetRemoteData = .ResponseBody
	End With
	Set Retrieval = Nothing
	Set Ads = Server.CreateObject("Adodb.Stream")
	With Ads
		.Type = 1
		.Open
		.Write GetRemoteData
		.SaveToFile server.MapPath(LocalFileName),2
		.Cancel()
		.Close()
	End With
	Set Ads=nothing
end Function 
Set UpFileObj = New UpFile_Class
UpFileObj.GetData(102400000000000000)
AutoReName = "2"
ClueOn_Msg = ""
No_UpFileTF = True
AppearErr = False
  name=UpFileObj.Form("name")
  laiy=UpFileObj.Form("laiy")
  idc=UpFileObj.Form("idc")
  TP=UpFileObj.Form("TP")
  lid=UpFileObj.Form("lid")
  if TP<>"1" then
if name="" or laiy="" or lid="" then
Call error("各项都要填写！")
end if
set rs1=server.CreateObject("adodb.recordset")
		sql1="select * from wjfile"
		rs1.open sql1,conn,1,3
		Rs1.addnew
		Rs1("name")=name
		Rs1("times")=now()
		Rs1("lid")=lid
		Rs1("laiy")=laiy
		Rs1("typeID")=1
		Rs1.Update
		Rs1.close
		Set Rs1=nothing

		
end if
set rs2=server.CreateObject("adodb.recordset")
		sql2="select top 1 id from wjfile order by id desc"
		rs2.open sql2,conn,1,1            
                idc=rs2("id")
		Rs2.close
		Set Rs2=nothing
dim id,g,s_geshi,s_s_geshi,nums
s_geshi="jpeg,jpg,gif,bmp,tiff,png"
g=UpFileObj.Form("nums")
s_s_geshi=split(s_geshi,",")
g=clng(g)
j_geshi=split(s_geshi,",")
d_dizhi=""
for i=1 to g
	gfile=lcase(UpFileObj.Form("file"&i))
	geshi=lcase(mid(gfile,instrrev(gfile,".")+1))
	sc=false
	for ii=0 to ubound(j_geshi)
		if geshi=j_geshi(ii) then
			sc=true
			exit for
		end if
	next
	if sc=false then
		response.write("文件"&i&"图片格错误<br/>")
	else
	dim ranNum,picname
		if isfile(gfile) then
			randomize
			ranNum=int(900*rnd)+100
			picname=year(now)&strMonth&strDay&hour(now)&minute(now)&second(now)&ranNum
		call saveremotefile("/pic/"&picname&"."&geshi,gfile,"")
'取文件大小
dim fso,f,filesize
Set fso=CreateObject("Scripting.FileSystemObject") 
if fso.FileExists(server.mappath("/pic/"&picname&"."&geshi)) then 
Set f=fso.GetFile(server.mappath("/pic/"&picname&"."&geshi)) 
filesize=f.size 
else
filesize=0
end if
Set fso = nothing
		set rs1=server.CreateObject("adodb.recordset")
		sql1="select * from uppic"
		rs1.open sql1,conn,1,3
		Rs1.addnew
		Rs1("picurl")="/pic/"&picname&"."&geshi
		Rs1("YD_size")=int(filesize/1024)
		Rs1("format")=geshi
		Rs1("lid")=idc
		Rs1.Update
		Rs1.close
		Set Rs1=nothing
		end if
	end if
next
	Set FileObject = Nothing
Set Fso = Nothing
		response.write("全部图片文件保存成功<br/>")
%>
<a href="picview.asp?sid=<%=sid%>&amp;id=<%=idc%>&amp;lid=<%=lid%>">[查看图片]</a><br/>
<a href="piclist.asp?sid=<%=sid%>&amp;lid=<%=lid%>">[图片列表]</a><br/>
<a href='picdl.asp?sid=<%=sid%>'>[图片类别]</a><br/>
<a href="../index.asp?sid=<%=sid%>">[后台管理]</a><br/>
<%response.write""
call head3()%>
