但是图片可以是svg的话
function saveAs(Url,filename){
var blob=new Blob([''], {type:'application/octet-stream'})
var url = webkitURL.createObjectURL(blob)
var a = document.createElementNS(xhtml,'a')
a.href = Url
a.download = filename
var e = document.createEvent('MouseEvents')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
webkitURL.revokeObjectURL(url)
2. saveAs(data,"new.svg")
用JSPSMART处理,参考下面代码实现:
<%
//程序初始化 下面设置成要保存的文件夹。
String path_tmp = request.getRealPath("/") + "Upload"
String filename_p = "Test"
String path_new = request.getRealPath("/") + "Upload\\" + filename_p
//文件上传。
JavaScript一种直译式脚本语言,是一种动态类型、弱类型、基于原型的语言,内置支持类型。它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本语言,最早是在HTML(标准通用标记语言下的一个应用)网页上使用,用来给HTML网页增加动态功能。
JS:
使用JS实现单击连接保存图片2种形式都可以第一种:
<script>
function SaveAs5(imgURL)
{
var oPop = window.open(imgURL,"","width=1, height=1, top=5000,
left=5000")
for(oPop.document.readyState != "complete")
{ if (oPop.document.readyState == "complete")break}
oPop.document.execCommand("SaveAs")oPop.close()
}
</script>
<img src="t_screenshot_17616.jpg" id="DemoImg" border="0"
onclick="SaveAs5(this.src)">
第二种:
<script>function SaveAs5(imgURL)
{
var oPop = window.open(imgURL,"","width=1, height=1, top=5000,
left=5000")
for(oPop.document.readyState != "complete")
{ if (oPop.document.readyState == "complete")break}
oPop.document.execCommand("SaveAs")oPop.close()
}
</script>
<img src="../t_screenshot_17616.jpg" id="DemoImg" border="0">
<a href="#" onclick="SaveAs5(document.getElementByIdx_x('DemoImg').src)">
点击这里下载图片 </a>
PHP:
<a href="test.php?url=uploads/1112/1-11122212201R28.jpg">下载</a>
test.php文件代码:
<?php
$dir=$_GET['url'] //获取图片地址$file = fopen($dir,"r") // 打开文件
Header("Content-type: application/octet-stream")
Header("Accept-Ranges: bytes")
Header("Accept-Length: ".filesize($dir))
Header("Content-Disposition: attachment filename=" . $dir)
echo fread($file,filesize($dir))
fclose($file)
exit
?>