<%@ codepage ="936" %>
<%charset="gb2312"%>
<%

Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache"


my_url="localhost" 
SQLServerName = "(local)" 
SQLDBUserName = "sa"             
SQLDBPassword = "820201"       
SQLDBName = "mofahe"
Set conn = Server.CreateObject("ADODB.Connection") 
conn.Open"Provider=SQLOLEDB.1;user id="&SQLDBUserName&";password="&SQLDBPassword&";initial catalog="&SQLDBName&";data source="&SQLServerName&";"

Dim action,url
action=request("action")
url=request("url")
If action="getnet" Then
	If InStr(LCase(url),"http://localhost")>0 Then   '是本地图片
		response.write url
		response.end
	else
		function MakedownName()
		dim fname
		Randomize
		fname = now()
		fname = replace(fname,"-","")
		fname = replace(fname," ","") 
		fname = replace(fname,":","")
		fname = replace(fname,"PM","")
		fname = replace(fname,"AM","")
		fname = replace(fname,"上午","")
		fname = replace(fname,"下午","")
		fname = int(fname) + int((100-1+1)*Rnd + 1)
		MakedownName=fname
		end function 

		'生成文件夹子程序
		sub add_myfso (wjj)
			set myfso = Server.CreateObject("Scripting.FileSystemObject")
			If myfso.FolderExists(server.MapPath(wjj))=False Then
				myfso.CreateFolder server.MapPath(wjj)
			End If
			set myfso=nothing
		end Sub
		bh=year(date) & right("00"&month(date),2) & right("00"&day(date),2)
		formPath="/UploadFiles/"&bh
		call add_myfso(formPath)

		DefPic=url
		fileExt=Right(DefPic,4)
		if int(instr(lcase(DefPic),".asp"))>0 or int(instr(lcase(DefPic),".asa"))>0 then
			response.write url
			response.end
		end If
		If LCase(fileExt)<>".jpg" And LCase(fileExt)<>".gif" And LCase(fileExt)<>".png" And LCase(fileExt)<>".bmp" Then
			fileExt=".jpg"
		End if
		set xmlhttp=server.createobject("MSXML2.serverXMLHTTP")
		xmlhttp.open "GET",url,false
		xmlhttp.send()
		if err.number<>0 then err.Clear 
		if xmlhttp.readystate<>4 then
			response.write url
			response.end
		Else
			img=xmlhttp.ResponseBody
			set objAdostream=server.createobject("ADODB.Stream")
			objAdostream.Open()
			objAdostream.type=1
			objAdostream.Write(img)

			FileName=MakedownName()&fileExt

			set myfso = Server.CreateObject("Scripting.FileSystemObject")
			if myfso.FileExists(server.mappath(formPath&"/"&FileName))=false then
				objAdostream.SaveToFile(server.mappath(formPath&"/"&FileName))
				objAdostream.SetEOS
				set objAdostream=nothing
			end If

			url="http://localhost"&formPath&"/"&FileName
		end if
		set xmlhttp=Nothing

		response.write url
	End if
End If
If action="delimg" Then

	Function noOwner(nstr)
		If nstr<>"" then
			Set rst= Server.CreateObject("ADODB.Recordset")
			sqlt="select id from A_slide where slide_images like '%"&nstr&"%'"
			rst.open sqlt,conn,1,1
			If Not (rst.bof And rst.eof) Then
				noOwner=False
			Else
				noOwner=true
			End if
		Else
			noOwner=false
		End if
	End Function

	If InStr(LCase(url),"http://localhost")>0 Then   '是本地图片
		PicPath=Replace(url,"http://localhost","")
		If PicPath<>"" And Not IsNull(PicPath) And PicPath<>"/upload/conver/demo_img_0.jpg"  Then

		  If noOwner(PicPath) Then
			Set fso = Server.CreateObject("Scripting.FileSystemObject")
			strRubbishFile=server.MapPath(PicPath)
			if fso.FileExists(strRubbishFile) then
				fso.DeleteFile(strRubbishFile)
			end if
			set fso=Nothing
		  End If
		End If
	End if
	response.write "0"
End If

%>