ASP 抓取远程图片,自动保存图片

ASP 抓取远程图片,自动保存图片,通过剪切板,拷贝网上的图文混排的文字,到编辑器粘贴,图片即可保存在本地,这样可以大大的减轻,因是远程图片,外部更改后,本地无法显示的问题。

核心代码:

function SaveRemoteFile(LocalFileName, RemoteFileUrl)
dim Ads, Retrieval, GetRemoteData
Set Retrieval = Server.CreateObject(“MSXML2.XMLHTTP”)
With Retrieval
.Open “Get”, RemoteFileUrl, False, “”, “”
.Send
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

SaveRemoteFile=1
End function
%>

应用示例

<input name=”body” type=”text” />
<input type=”submit” name=”Submit” value=”提交” />
</form>
<p>
<%
if request.QueryString(“action”)=”test” then
‘取得文章内容
Content =Request.Form(“body”)
‘开始保存图片
aa = “qq/a.gif” ‘这里AA可以从Content中得到文件名。
a1 = SaveRemoteFile(aa,Content)
‘显示结果
response.Write(“<img src=’qq/a.gif’>”)
Response.Write(Content)
Response.End()
end if
%>

标签