3

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?

2 Answers 2

2

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.

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

Comments

1

In my case. I get binary file from JS request array : $file['content'] format of Uint8Array.

            <?php
            $packed = pack("c*", ...$file['content']);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.