aquadeluxe Posted April 2, 2008 Share Posted April 2, 2008 I'm having trouble with this code. <?php $path_to_file = "file_e.bin"; $fp = fopen($path_to_file, "w+b"); fseek($fp, 0x103, SEEK_SET); fwrite($fp, pack('H*', '6E')); fclose($fp); ?> What is happening is the file is normally a very long file, but it then just gets truncated to 0x103, and all the hex before 0x103 gets turned into 00. Does anyone have a solution? Link to comment https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/ Share on other sites More sharing options...
aquadeluxe Posted April 3, 2008 Author Share Posted April 3, 2008 bump Link to comment https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/#findComment-508244 Share on other sites More sharing options...
MadTechie Posted April 3, 2008 Share Posted April 3, 2008 You have stated what happens but not what you expect.. from looking at the code i assume you didn't expect the zeros change fwrite($fp, pack('H*', '6E')); should be fwrite($fp, pack('H*', 6E)); also $fp = fopen($path_to_file, "w+b"); should be $fp = fopen($path_to_file, "r+"); Link to comment https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/#findComment-508271 Share on other sites More sharing options...
aquadeluxe Posted April 3, 2008 Author Share Posted April 3, 2008 I want to just change the 0x103 offset and keep all of the other bytes in tack. When I change from w+b to r+ without changing the pack statement, it then returns the whole file, but 0x103 is still in it's original form. When I change omit the single quotes on 6E, it just gives a T_STRING error. Link to comment https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/#findComment-508326 Share on other sites More sharing options...
MadTechie Posted April 3, 2008 Share Posted April 3, 2008 try 0x6E Link to comment https://forums.phpfreaks.com/topic/99157-help-with-fwrite-pack/#findComment-508329 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.