neohunter Posted November 27, 2006 Share Posted November 27, 2006 hi, im just learning php since one month ago. this is my first post on this forum! so i wanna say hi to everybody ^^..now i hope you can help me... i need to generate a custom binary file... let me explain you fast...this is the format of the file[code]TRIADPATCHERPATCHBIN -> main -> this is the header[00][00][00][00] -> filecount -> this bytes is a count of the files inside the file------------------------------- NOW FOR EVERY FILE -------------------[0C][00][00][00] -> filenamecount -> the numbers of bytes in the filenameoriginalfilename -> file_from -> the name[0C][00][00][00] -> file_tonamecount -> the numbers of bytes in the file_todestinefilename -> file_toname -> the name of the file_to =P[07][00][00][00] -> contentcount -> the lenght in bytes Content -> content -> the content of this fileand the last block repeat for every file inside the file...[/code]well, so i start making a function; make_tpp($files)files is an array:$files = array('file_from.grf' => 'file_to.grf');now i need to use the funcion pack for generate the file... i tried witout the array.. i did something like this...[code]$file_from='file_from.grf';$file_to='file_to.grf';$content='content test';$data= pack('a20VVa*Va*Va*','TRIADPATCHERPATCHBIN',1,strlen($file_from),$file_from,strlen($file_to),$file_to,$strlen($content),$content); #next i save it to a file...if(($fp=fopen('test.hex',"wb"))){ fwrite($fp,$data); fclose ($fp); }[/code]And thats works perfectly! but i need to pass more that one file, so i need a way to pass multi parameters to the pack function...[code]foreach ($files as $file_from => $file_to){ #[0C][00][00][00] -> filenamecount -> V $hex_format .= 'V'; $hex[] = strlen($file_origen); #originalfilename -> file_origen -> a* $hex_format .= 'a*'; $hex[] = $file_origen; #[0C][00][00][00] -> destfilenamecount -> V $hex_format .= 'V'; $hex[] = strlen($file_dest); #destinefilename -> destinefilename -> a* $hex_format .= 'a*'; $hex[] = $file_dest; #[07][00][00][00] -> contentcount -> V $_content = file_get_contents($file_origen); $hex_format .= 'V'; $hex[] = strlen($_content); #content $hex_format .= 'a*'; $hex[] = $_content; }pack($hex_format,???????????);[/code]do you understand me????!?!?!?!?!??! Quote Link to comment Share on other sites More sharing options...
neohunter Posted November 27, 2006 Author Share Posted November 27, 2006 try to explain better... the pack funcion ispack(format, parm1, parm2, parm3... etcetc);so, when the array containt one file i need to give to the pack funcion 8 parameters. but when the array containt 2 files i will need to give 14 parameters to the pack function!i just dont know how to do that... Quote Link to comment Share on other sites More sharing options...
fert Posted November 27, 2006 Share Posted November 27, 2006 why can't you just pass the array to the function? Quote Link to comment Share on other sites More sharing options...
neohunter Posted November 27, 2006 Author Share Posted November 27, 2006 i try it...pack($hex_format,$hex);but doesnt work... Quote Link to comment Share on other sites More sharing options...
neohunter Posted November 27, 2006 Author Share Posted November 27, 2006 OK I SOLVED IT! JUST CONCATENATING ( .= )#the header--$data= pack('a20V','TRIADPATCHERPATCHBIN',2); #name V#and the foreach goes here...$data.=pack('Va*Va*Va*',strlen($file_from),$file_from,strlen($file_to),$file_to,strlen($content),$content);#SUCCES!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.