$typefile){ if($typefile == $file){ $type = $typeid; } } if($type==-1)die("We don't recognize filetype <$file>, sorry...\n"); $binary = file_get_contents($binpath.$file); $length = strlen($binary); $offset = strlen($output); $subarr['type']=$type; $subarr['version']=$version; $subarr['name']=$file; $subarr['offset']=$offset; $subarr['length']=$length; $toc[] = $subarr; $output.=$binary; } $jtoc = json_encode($toc); $tocsize = strlen($jtoc); if($tocsize>$tocmaxsize)die("TOC is too big! adjust size and try again\n"); $output = substr_replace($output,$jtoc,0,strlen($jtoc)); file_put_contents($binpath."AP_FW_Pack.bin", $output); print_r($toc); echo "All done.\n";