PHP receives string instead of binary data when posting ArrayBuffer from IE11

I’m having trouble with binary file uploads in Internet Explorer 11. My JavaScript code reads a file and sends it as binary data to my PHP backend.

var fileBuffer = <result from FileReader readAsArrayBuffer>;
var httpRequest = new XMLHttpRequest();
httpRequest.open('POST', targetUrl);
httpRequest.setRequestHeader('Content-Type', 'application/octet-stream');
httpRequest.setRequestHeader('CustomHeader', headerValue);
var bufferView = new DataView(fileBuffer);
httpRequest.send(bufferView);

On the server side I capture the request like this:

<?php
$inputData = file_get_contents('php://input');
error_log($inputData);
?>

The weird thing is that Chrome and Firefox work perfectly fine and I can see the actual binary content in my logs. But when I test with Internet Explorer 11, instead of getting the binary image data, I only see the text [Object object] in my PHP logs. How can I handle this IE11 issue and properly receive the binary data?

I had the same issue and switched to using a Blob instead of messing with ArrayBuffer conversions. IE11 handles Blobs way better for binary uploads. Just wrap your buffer like this: var blob = new Blob([fileBuffer], {type: ‘application/octet-stream’}); then send it with httpRequest.send(blob). Blob support is much more consistent across IE versions, and you don’t have to deal with all the typed array weirdness. I’ve used this for image uploads and it handles binary data perfectly without those object serialization problems.

Ugh, IE11 strikes again! Skip the DataView wrapper and send the ArrayBuffer directly - just use httpRequest.send(fileBuffer). IE11 gets weird with DataView objects but usually handles ArrayBuffers fine. Try that before converting to Uint8Array.

Had this exact problem - spent hours pulling my hair out! IE11 has a weird quirk where it won’t serialize ArrayBuffer or DataView objects properly through XMLHttpRequest. Instead of sending the actual binary data, it just converts the object to a string, which is why you’re getting ‘[Object object]’ in your PHP logs. Here’s what fixed it for me: convert the ArrayBuffer to a Uint8Array before sending. Replace your last two lines with: var uint8Array = new Uint8Array(fileBuffer); httpRequest.send(uint8Array); This makes IE11 handle the binary data correctly instead of trying to stringify the DataView. Tested it on IE11, Chrome, and Firefox - works perfectly on all of them. Your PHP code stays the same since you’ll still get proper binary data through php://input.

This topic was automatically closed 6 hours after the last reply. New replies are no longer allowed.