Skip to content
Advertisement

PHP fclose writing 0x30 0x33 to end of file

I am tring to create a binary file from a hex caractere array, it works as expected on the file but fclose writes unexpected 0x31, 0x30 and 0x33 bytes at the end of the file.

This behavior does not exist in ruby for example, anyone knows why?

$bytes_array = str_split('1f8b08082907ac5a0400425231335f543133343535395f52494345433135305f343432373800cd96596e83301086df2bf50e39823dbb5f5ba552a4b66996deff2a1d0cc16c7d098b1809bc8d07cfa77f00c1b76bc47b44624ea136668d260ad1fb82d54c8c163082890fd5e4d0b17a0bd50d42b2c0658abc6f601e3281c7f088aac1a31f262c74cc87972801a2fd5c4f5f9dc57c0ea93a836d6567b16f0ed5325244f61de130d35e5ffea1050925621eb4b402ba9722ca3b74423cd2a85c2924f0a64ce1142d421a9f644c2b3fd08eb7fbf9f27b5c8016ac470bd92013a86e455b9ea8a862374423aa3a1714a1072dcc57a165d6d04ac8a3834c692bd3fa387ddeafe7db4c5a84b0a6b650d4531fd04253105f1ad1aa98e41b064f85cb14f2f3b41a55d5b816a0b5a6b65a5ad0a1452a9e34f65e3b8faacbbe91dd9f9ba999da5a9a166e410b7bdab200092669d56e89d35e69d116b4a8a72d028dd27b49fb6aeb0615d0b612695f95c85bd0e2aeb6888c85b4dd3fd41690d15eb5255bd0d23ead08436d359c72e3244b25c2be68e916b4ac5789a80030fc2696dfd314d2cc3f0890b568d902b4fe00839a3179cc0b0000', 2);
$file = fopen("arq.gzip", "w+");
$val = $bytes_array[0];
eval(' $byte = ' . "0x$val;");
fwrite($file, chr($byte));
fclose($file);

and this results on this file:

hex file preview

Well looks like this does not afect the final file, i can use the gzip normally even with this 0x31 0x33 0x30. But will be good to know what this means.

Advertisement

Answer

Well looks like this does not afect the final file, i can use the gzip normally even with this 0x31 0x33 0x30.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement