Save byte array to file in PHP
You need to package the array and save . Well roughly since you did not give details of what you want, nor demonstrated what you already did you can do so:
foreach ($imagem as $byte) {
$binario .= pack("C", $byte);
}
$arquivo = fopen("arquivo.bin", 'wb');
fwrite($arquivo, $binario);
fclose($arquivo);
The exact way can vary according to your needs.
If the format is already in binary, you can just do the recording:
$arquivo = fopen("arquivo.bin", 'wb');
fwrite($arquivo, $imagem);
fclose($arquivo);