I'm trying to develop a mechanism to download a canvas as an image by forcing download via php. the following code works in chrome desktop but NOT on an Android 2.3 stock browser.
<script> function downloadImage()
{
document.getElementById('action').value = 'downloadfile';
document.getElementById('source').value = document.getElementById('finalimage').src;
document.getElementById('user').value = userId;
document.getElementById('imageForm').submit();
}
</script>
<html>
<form id="imageForm" action="" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="source" id="source" value=""/>
<input type="hidden" name="action" id="action" value="savefile"/>
<input type="hidden" name="user" id="user" value=""/>
</form>
</html>
<?php
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"colouringbook-page.jpg\"");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
header("Content-transfer-encoding: binary");
$source = $_REQUEST['source'];
$source = base64_decode(substr($source, strpos($source, ",")+1));
header("Content-Length: " . strlen($source));
print $source;
exit;
?>
The problem I am getting is firstly a "Download unsuccessful". Then when I DO manage to get a successful download the image is corrupted.
Looks like it can be an android stock browser bug. I was able to save the image to the server but still couldn't output the buffer from there to download the image. I had to output a regular html tag then do a "save as" on the android to download the image.
Whats seems to be happening is that the Android device is attempting to "re-request" the process which is POSTED logic process. Apparently the device download manager doesn't POST anything.
The solution I came up with was to use a session to store the information