How to read/convert a file into a byte array?
Posted: Fri Jan 20, 2006 2:40 am
I've done my best to find something that clearly describes how read a file into a byte array, but I'm still missing something, after hours of trying. Specifically, I'm uploading an image file to one server, then I need to read that file into a byte array so I can make a method call which takes the byte array as input. I start with:
and pass $dataString to variations of:
I've also looked at using pack/unpack, but I haven't been able to figure them out yet.
I've been banging my head against a wall here, and I suspect that there's a really easy way to do this that I'm missing. If someone out there has done this, or knows how, I would *really* appreciate the help!
Code: Select all
$dataString = file_get_contents( $uploadedFile );Code: Select all
function asc2bin ($temp) {
$data = array();
$len = strlen($temp);
for ($i=0; $i<$len; $i++)
$data[$i]=sprintf( "%08b", ord( substr( $temp, $i, 1 ) ) );
return $data;
}I've been banging my head against a wall here, and I suspect that there's a really easy way to do this that I'm missing. If someone out there has done this, or knows how, I would *really* appreciate the help!