Let's say I have a PHP script that has a bunch of binary data in it that needs to be processed client side in JavaScript.
<?php
$binary_data = file_get_contents( "file.data" );
?>
And I have a JavaScript function that is meant to process it from an ArrayBuffer:
<script type="text/javascript">
function processData( arrayBuffer ) {
...
}
</script>
Passing it directly won't work because it's binary data so this won't work:
<?php
$binary_data = file_get_contents( "file.data" );
echo <<<EOF
<script type="text/javascript">
var binaryData = '{$binary_data}';
processData( binaryData );
function processData( arrayBuffer ) {
...
}
</script>
EOF;
?>
How can I pass the PHP variable $binary_data into a JavaScript variable ArrayBuffer in a single page load?