Question

I'm following the tuitions on XMLHttpRequest 2 from :

https://developer.mozilla.org/en/DOM/XMLHttpRequest/Sending_and_Receiving_Binary_Data and http://www.html5rocks.com/en/tutorials/file/xhr2/#toc-send-arraybuffer

They're great tutorials for the client side, and here is a working extract from my script:

var imagebuffer = new ArrayBuffer(size);  // create the readonly memory buffer
var imagedata= new Uint8Array(imagebuffer); // create a view to manipulate data

// do some cool stuff with imagedata

var exchange=new XMLHttpRequest();
exchange.open("POST",url,true);
exchange.send(arraybuffer);

So far so good, and I can see from the both client and server control panels that plenty of data is being transferred.

Here's my problem: how do I access the ArrayBuffer with PHP at the server? I'm used to the $_POST superglobal wanting parameters passing from a HTML form so it can be accessed as an array but I can't find any reference for how to access this binary array and stick it in my MySQL database.

Was it helpful?

Solution

Okay - I've figured it out. My server side PHP opens with:

$data = file_get_contents('php://input');
$mysql_blob = base64_encode($data);

which is now in a format ready for inserting (for example) into MySQL as a BLOB format.

Works like a charm!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top