If you are writing a binary file on a Windows system, you should add a 'b' flag.
$fp = fopen( "binary_file", "wb" ); and read them like this: $fp = fopen( "binary_file", "rb" );