Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the Save as ..dialog on click of the image?

Here is the code.

On click of the link , the save as dialog should open

<a href="http://www.experts-exchange.com/xp/images/newNavLogo.png" target="_new">
<img src="http://www.experts-exchange.com/xp/images/newNavLogo.png" align="left" alt="" />
</a>

How can we achive this using jQuery, or javaScript?

like image 567
Wasim Shaikh Avatar asked Nov 25 '22 17:11

Wasim Shaikh


1 Answers

If you are using PHP or any other platform you can always use the force download technique.

This might help:

<?php 
$file = 'tag_cloud.gif';
if(!file){
  // File doesn't exist, output error
  die('file not found');
}else{
  // Set headers
  header("Cache-Control: public");
  header("Content-Description: File Transfer");
  header("Content-Disposition: attachment; filename=$file");
  header("Content-Type: image/gif");
  header("Content-Transfer-Encoding: binary");
  // Read the file from disk
  readfile($file);
}
?>

Call the above script as ajax in the click event of image.

Cheers

like image 155
Hasan Avatar answered Dec 15 '22 17:12

Hasan