I show an image in tag which is created by GD PHP by merging two images. Something like this
$('#output_images').append(<img src="MergeIcons.php?icon1='+firstIcon+'&icon2='+secondIcon+'" /></li>');
This outputs the image correctly, now I want to make this as a clickable image which on click downloads the image.
Something like
$('#output_images').append('<li><a href="DownloadNewIcon.php?file="MergeIcons.php?icon1='+firstIcon+'&icon2='+secondIcon+'"><img src="MergeIcons.php?icon1='+firstIcon+'&icon2='+secondIcon+'" /></a></li>');
I am not sure what should be the values for href? If I handle the download in different PHP file then what should be the file path?
My PHP code for merging two icons,
header('Content-Type: image/png');
imagepng($dest);
To make the user download the file automatically, add this near the Content-Type header:
header('Content-Disposition: attachment; filename="'. $generateSomeFilename .'"');
This will cause most browsers to not output the image but immediately show the save as dialog.
You'll need to add an event handler and call the PHP again:
var url = 'MergeIcons.php?icon1='+firstIcon+'&icon2='+secondIcon;
var img = $('<img>', {'src':url}).on('click', function()
{
document.href = url + '&download=true';
});
$('#output_images').append(img);
Then, add the Content-Type header when you recieve the "download = true" paramater.