js 点击按钮下载图片,另存为


js:

1 $(document).on('click',"#xiazai",function(){ 2             imgurl = $(".img-box").find('img').attr('src'); 3             window.open('/index/download.html?dir='+imgurl); 4         });

服务端

 1 public function actionDownload($dir,$name){  2         header('Pragma: public'); // required
 3         header('Expires: 0'); // no cache
 4         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');  5         header('Cache-Control: private',false);  6         header('Content-Type: application/force-download');  7         header('Content-Disposition: attachment; filename="'.$name.'.jpg"');  8         header('Content-Type: application/octet-stream; name=' . $dir);  9         header('Content-Transafer-Encoding: binary'); 10         header('Connection: close'); 11         readfile($dir); 12         exit(); 13     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM