Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is how I do it (you'll probably want to add some sort of validation in the PHP to prevent random uploading):</p> <p>JS:</p> <pre><code>function saveImage(){ var xmlhttp; xmlhttp=((window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { //do something with the response } } xmlhttp.open("POST","myImageSavingScript.php",true); var oldCanvas = document.getElementById('line1').toDataURL("image/png"); var img = new Image(); img.src = oldCanvas; xmlhttp.setRequestHeader("Content-type", "application/upload") xmlhttp.send(oldCanvas); } </code></pre> <p>PHP:</p> <pre><code>&lt;?php $im = imagecreatefrompng($GLOBALS["HTTP_RAW_POST_DATA"]); imagepng($im, 'filename.png'); ?&gt; </code></pre> <p>And this is a variation if you need to pass other parameters along with it:</p> <p>JS (just the mod):</p> <pre><code>var oldCanvas = document.getElementById('line1').toDataURL("image/png"); var img = new Image(); img.src = oldCanvas; var params=oldCanvas+"&amp;someOtherParameter=parameterValue"; xmlhttp.setRequestHeader("Content-type", "application/upload") xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.send(params); </code></pre> <p>PHP:</p> <pre><code>&lt;?php $params=explode('&amp;',$GLOBALS["HTTP_RAW_POST_DATA"]); $val=split("=",$params[1]); $someOtherParam=urldecode($val[1]); $imgsrc=str_replace(' ','+',$params[0]); $im = imagecreatefrompng($imgsrc); imagepng($im, 'filename.png'); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload