suikki Posted January 27, 2013 Share Posted January 27, 2013 I cannot find how to write a binary file such as as data into a .bmp image file.I tried the following but it simply writes ascii bytes of the characters instead of their binary value $head[0]= "1";$head[1]= "12";$head [2] ="34"; $filein=fopen('code.bmp','wb'); //File to be convertedfor ($i=0; $i < 3; ++$i) {fputs ($filein,$head[$i],2);}fclose($filein); Chuck S. Link to comment Share on other sites More sharing options...
jeffman Posted January 27, 2013 Share Posted January 27, 2013 For starters, don't put the numbers in quotation marks. Link to comment Share on other sites More sharing options...
suikki Posted January 27, 2013 Author Share Posted January 27, 2013 Solution found:$head[0]= dechex("120");$head[1]= dechex("112");$head [2] = dechex("64");if (!unlink('code.bmp')) echo "Could not delete this file"; else echo "new file";$filein=fopen('code.bmp','wb'); //File to be convertedfor ($i=0; $i < 3; ++$i) {fputs ($filein,$head[$i],2);}fclose($filein); thanks for your comments Link to comment Share on other sites More sharing options...
Ingolme Posted January 27, 2013 Share Posted January 27, 2013 That sounds weird. If you want to write binary characters you should use the chr() method. Using dechex() is just going to print the hexadecimal digits in string form into the file, literally characters like "5" and "F". Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now