I have a Uint8Array which have 10000 bytes on Javascript side.
var data = new Uint8Array(10000) ;
I want to send it to PHP and create a file with it:
$.ajax({
url:'saver.php',
type: 'POST',
contentType: 'application/octet-stream',
data:data,
processData: false
});
This ajax is sending data (I see it on "Request Payload" section on console) but there is no $_POST record, $_POST array is empty, just silent. How to grab it properly?
This seems to be a known behavior. For an array of 10000 bytes, you should be able to use
$rawPost = file_get_contents('php://input');
to get your data from the request instead of checking the $_POST variable.
Note that this method loads the data in-memory, so if the data are too large, you will get an error.
In my case. I get binary file from JS request array : $file['content'] format of Uint8Array.
<?php
$packed = pack("c*", ...$file['content']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With