[thelist] Binary file manipulation in PHP

Rick den Haan rick.denhaan at gmail.com
Wed Feb 13 10:26:51 CST 2008


David Menzel wrote:
> While I havnt done to much with binary files in php, i believe you need 
> the file_get_contents function.
> http://us.php.net/manual/en/function.file-get-contents.php
> 
> Also, you could try setting the binary flag on fread if you havnt already.
> 
> Good luck

Thanks, but getting the contents of the file is no problem. For example, to
get the version number (first 2 bytes in the file), I use:

$rHandler = fopen($sFilename, 'rb');
$binVersion = fread($rHandler, 2);

This moves the pointer, so to get the file type (the next 8 bytes), I can
then do

$binType = fread($rHandler, 8);

to get bytes 3 through 10.

The trick is, what do I need to do to $binVersion and $binType to get
something human-readable?

Thanks,
Rick.




More information about the thelist mailing list