How to save byte array to file in PHP?

1

I have a array which is an image that is saved in the DB, which method do I use to save to the hard drive?

    
asked by anonymous 16.01.2015 / 00:18

1 answer

3

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);
    
16.01.2015 / 00:35