file to binary php

PHP
$data = fopen ($image, 'rb');
$size=filesize ($image);
$contents= fread ($data, $size);
fclose ($data);

Source

Also in PHP: