var ev = document.createEvent("MouseEvents")
ev.initMouseEvent(
"click", true, false, window, 0, 0, 0, 0, 0
, false, false, false, false, 0, null
)
obj.dispatchEvent(ev)
}function export_raw(name, data) {
var urlObject = window.URL || window.webkitURL || window
var export_blob = new Blob([data])
var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
save_link.href = urlObject.createObjectURL(export_blob)
save_link.download = name
fake_click(save_link)
}
这个用jquery是无法实现的,需要用asp.net才能实现using System.Net
using System.IO
using System.Drawing.Imaging
/// <summary>
/// </summary>
/// <param name="savedir">本地保存路径</param>
/// <param name="imgpath">远程图片文件</param>
/// <returns></returns>
public string downRemoteImg(string savedir,string imgpath)
{
if (string.IsNullOrEmpty(imgpath))
return string.Empty
else
{
string imgName = string.Empty
string imgExt = string.Empty
string saveFilePath = string.Empty
imgName = imgpath.Substring(imgpath.LastIndexOf("/"), imgpath.Length - imgpath.LastIndexOf("/"))
imgExt = imgpath.Substring(imgpath.LastIndexOf("."), imgpath.Length - imgpath.LastIndexOf("."))
saveFilePath = Server.MapPath(savedir)
if (!Directory.Exists(saveFilePath))
Directory.CreateDirectory(saveFilePath)
try
{
WebRequest wreq = WebRequest.Create(imgpath)
wreq.Timeout = 10000
HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse()
Stream s = wresp.GetResponseStream()
System.Drawing.Image img
img = System.Drawing.Image.FromStream(s)
switch (imgExt.ToLower())
{
case ".gif":
img.Save(saveFilePath + imgName, ImageFormat.Gif)
break
case ".jpg":
case ".jpeg":
img.Save(saveFilePath + imgName, ImageFormat.Jpeg)
break
case ".png":
img.Save(saveFilePath + imgName, ImageFormat.Png)
break
case ".icon":
img.Save(saveFilePath + imgName, ImageFormat.Icon)
break
case ".bmp":
img.Save(saveFilePath + imgName, ImageFormat.Bmp)
break
}
img.Dispose()
s.Dispose()
return savedir + imgName
}
catch
{
return imgpath
}
}
}
使用方法:
如保存到本地的test目录:
Response.Write(this.downRemoteImg("test", "http://www.xxx.com/123.gif"))
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)