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