<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title$amp>amp$nbsp通过js保存图片到本地 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="" type="text/javascript"$amp>amp$lt/script>
<script>
function DownLoadReportIMG(imgPathURL) {
//如果隐藏IFRAME不存在,则添加
if (!document.getElementById("IframeReportImg"))
$('<iframe id="IframeReportImg" name="IframeReportImg" onload="DoSaveAsIMG()" width="0" height="0" src="about:blank"$amp>amp$lt/iframe$amp>apos$).appendTo("body")
if (document.all.IframeReportImg.src != imgPathURL) {
//加载图片
document.all.IframeReportImg.src = imgPathURL
}
else {
//图片直接另存为
DoSaveAsIMG()
}
}
function DoSaveAsIMG() {
if (document.all.IframeReportImg.src != "about:blank")
document.frames("IframeReportImg").document.execCommand("SaveAs")
}
</script>
</head>
<body>
<input type="button" value="download image" onclick="DownLoadReportIMG('')"$amp>amp$nbsp
</body>
</html>
<input name="save" type="submit" value="另存为" onClick="window.location='sava.php'"/>sava.php 主要是用在发送文件头,当然,这个Sava.php 也可以换成 file.RAR
<?php
$file = 'file.rar'
header("Content-length: " . filesize($file))
header('Content-Type: application/octet-stream')
header('Content-Disposition: attachmentfilename="'.$file.'"')
readfile("$file")
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)