Accessing ArrayBuffer from PHP $_POST after xmlHTTPrequest send()

我只是一个虾纸丫 提交于 2019-12-07 13:00:17

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/11301254/accessing-arraybuffer-from-php-post-after-xmlhttprequest-send

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!