I have a PHP array, which contains bytes, and the actual bytes represent a ZIP file (which contains multiple files inside the ZIP).
This is returned from a third party API, so I have no choice but to work with this format.
So I'm trying to convert this into the ZIP file.
Example of byte array returned by API:
[bytes] => Array
 => 37
 => 80
 => 68
 => 70
 => 45
 => 49
 => -46
... continues to close to 20,000
foreach($bytes as $byte)
$byteString .= $byte;
header("Content-Disposition: inline; filename='test.zip'");
$fp = fopen('/myfile.zip', 'wb+');
$byte1 = array_shift($bytes);
$byte2 = array_shift($bytes);
$byte2 = 0;
fwrite($fp, pack("n*", ($byte1 << 8) + $byte2));
With the help of an ascii table it's easy to decode the data you're receiving, and you will see that it starts with
which means that the returned data is in PDF format, not zip. Zip files start with PK, the initials of the inventor of the format, the late Phil Katz.
As a general note, knowing about the common file type signatures is quite useful and can save you lots of time.