binary write to file problem in mode r+b
I created a class which should creates new binary file (called 4.ip) in the case that the file does not exist. Method reset() does the job. Then I try to add some numbers from Ip to the file. I try to use binary mode but It looks like it corrupts the file. First value 0E is written correctly. I have marked the BOM which was created in the reset method (idk if is this right when it should be binary file.
To see the above, uncomment the die(); on line 413. Then to see the bellow, comment it back.
When I try to write the second value (line 415), the file looks corrupted, and all the 0000 disappear.
error on second fwrite
This is the source code
please see the lines 412-418.
Please help because I really cannot find out solution, and I am lost. Trying to solve this few days.
$scanIPs = new Scan_ips;
Yet I show you working version which is simplified. This uses no class:
so you can see how it works. The written data do not corrupt the file. But why I cannot use the class to do that?
have you tried the pack php function? you can see a demo: http://webtrick101.blogspot.com/2011...rray-data.html
I did check it before, but did not understand how it works. From the code on the link you posted what does mean the values 0x47, 0x49, 0x46 ? It is binary format? But it is not clear to me what does this:
does it join the binary data?
I was used to join binary data like this: chr(64) but it calles a function. So this is faster? And why not do it like this:
0x47 . 0x49 . 0x46 or foreach ($array as $binval) $str.=0x49 ???
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)