<!-- #include file="conn.asp" -->
<!-- #include file="check.asp" -->

<% 
 '===========================================================================================
	'软件名称：126 cms 视频影视管理系统
	'程序版权：126电影               '咨询QQ：479025
	'开发作者：magicblack(479025)    '官方网站：http://www.126oo.com/
	'Copyright (C) 2009 - ... 126oo.com  All Rights Reserved.
	'郑重声明:
	'    1、免费版本请在程序首页保留版权信息，并做上本站LOGO友情连接,商业版本无此要求;
	'    2、任何个人或组织不得以盈利为目的发布,修改,本软件及其他副本上一切关于版权的信息；
	'    3、126电影保留此软件的法律追究权利；
'==========================================================================================
%>

<%
response.Charset="GBK"

Response.Expires = 0  
Response.expiresabsolute = Now() - 1  
Response.addHeader "pragma", "no-cache"  
Response.addHeader "cache-control", "private"  
Response.CacheControl = "no-cache" 
Response.Buffer = True 
Response.Clear
Server.ScriptTimeOut=999999999

Response.Write "<style type='text/css'>"
Response.Write "body,td,th {font-size: 9pt;}"
Response.Write "a {font-size: 9pt;}"
Response.Write "a:link {text-decoration: none;}"
Response.Write "a:visited {text-decoration: none;}"
Response.Write "a:hover {text-decoration: none;}"
Response.Write "a:active {text-decoration: none;}"
Response.Write "</style>"

dim FromUrl,flName,fldr,GetNewsFold,i

FromUrl=request("url")
if FromUrl="" or left(FromUrl,7)<>"http://" then
response.write"请输入正确定的地址，如Admin_Upimg.ASP?Url=http://*****.gif"
response.end
end if

flName=request("path")
If Len(flName)<10 Then 
Response.write"无图片下载或地址错误"
response.End
End If 
fldr=""
If IsExists(flName)=True then 
response.write"<a target=_blank href="&flName&">"&flName&"</a>文件已存在<BR>"
response.Flush
else
GetNewsFold=split(flName,"/")
For i=0 to Ubound(GetNewsFold)-1
    if fldr="" then
	    fldr=GetNewsFold(i)
    else
	    fldr=fldr&"\"&GetNewsFold(i)
    end if
	If IsFolder(fldr)=false then
		CreateFolder fldr
	End if
Next

	SaveFiles FromUrl,flName
End if

Function GetImg(url)
	dim oSend ,SourceCode
	set oSend=createobject("Microsoft.XMLHTTP")
	SourceCode = oSend.open ("GET",url,false) 
	oSend.send()
	GetImg = oSend.responseBody
End Function

Function savefiles(from,tofile)
dim geturl,objStream,imgs
geturl=trim(from)
imgs=GetImg(from)
Response.Write "<a target=_blank href="&tofile&">"&tofile&"</a>&nbsp;保存成功：<font color=red>"&formatnumber(len(imgs)/1024*2,2)&"</font>Kb<BR>"
response.Flush
if formatnumber(len(imgs)/1024*2,2)>1 then
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type =1
objStream.Mode=3  
objStream.Open
objstream.write imgs
objstream.SaveToFile server.mappath(tofile),2
objstream.Close()
set objstream=nothing
else
Response.Write "保存失败：<font color=red>文件大小"&formatnumber(len(imgs)/1024*2,2)&"Kb，小于1K</font><BR>"
response.Flush
end if
end function

'检测文件是否存在
Function IsExists(filespec) 
	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")
	If (fso.FileExists(server.MapPath(filespec))) Then
	IsExists = True
	Else
	IsExists = False
	End If
End Function

'检测文件夹是否存在
Function IsFolder(Folder)
	dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
	If FSO.FolderExists(server.MapPath(Folder)) Then  
	IsFolder = True
	Else
	IsFolder = False
	End If
End Function

'新建文件夹
Function CreateFolder(fldr) 
on error resume next
	Dim fso, f
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set f = fso.CreateFolder(Server.MapPath(fldr))
	CreateFolder = f.Path
	Set f=nothing
	Set fso=nothing
End Function
%>