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 }