0

I want to send the canvas data to the server side as image. I have been making an HTTP post request, but i am not able to get the data at server side. $_POST is empty but when i console the same object at JS side i get the image data.

this is the JS side

var XHR = new XMLHttpRequest(); var vvFD="image=" + JSON.stringify(document.getElementById('canvas').toDataURL("image/png")); console.log(vvFD); XHR.upload.addEventListener('progress', uploadProgress, false); XHR.addEventListener('load', uploadFinish, false); XHR.addEventListener('error', uploadError, false); XHR.addEventListener('abort', uploadAbort, false); XHR.open('POST', 'example_upload/upload1.php'); XHR.send(vvFD); 

and the PHP side is...

 if(!empty($_POST)) { //do stuff } else { echo "_POST is empty"; } 

I am getting the message _POST is empty.

Any one can here help

Thanks in advance

1 Answer 1

1

I'm not entirely sure how your JS works, but I have a feeling it's sending the image in the body section of the HTTP request. $_POST won't pick that up on the server side.

Try:

$GLOBALS["HTTP_RAW_POST_DATA"]; 

There is an example in the manual which will output the headers from your HTTP request. apache_request_headers()

Between these two, you should be able to capture everything coming into your php script.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, i just have found the answer by searching different forums and the answer that i found is similar with that you, i was also missing the same thing that you mentioned above. Here is the link of the answer that i found is worldofwebcraft.com/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.