PHP Array of Bytes to Zip File -
i have php array, contains bytes, , actual bytes represent zip file (which contains multiple files inside zip).
this returned third party api, have no choice work format.
so i'm trying convert zip file.
example of byte array returned api:
[bytes] => array ( [0] => 37 [1] => 80 [2] => 68 [3] => 70 [4] => 45 [5] => 49 [6] => -46 ... continues close 20,000 )
i have tried getting browser return creating complete byte string, , adapting browser headers... using:
foreach($bytes $byte) { $bytestring .= $byte; } header("content-type: application/zip"); header("content-disposition: inline; filename='test.zip'"); echo $bytestring;
this create zip file, it's invalid / corrupted.
i have tried found elsewhere on stackoverflow:
$fp = fopen('/myfile.zip', 'wb+'); while(!empty($bytes)) { $byte1 = array_shift($bytes); $byte2 = array_shift($bytes); if(!$byte2) { $byte2 = 0; } fwrite($fp, pack("n*", ($byte1 << 8) + $byte2)); } close($fp);
but again, zip created, it's invalid / corrupted.
any pointers, appreciated.
thanks
with of ascii table it's easy decode data you're receiving, , see starts with
%pdf
which means returned data in pdf format, not zip. zip files start pk, initials of inventor of format, late phil katz.
as general note, knowing common file type signatures quite useful , can save lots of time.
Comments
Post a Comment