I'm creating a class to stream a ZIP file from PHP.
The output is absolutely fine when opening in WinRAR, Windows compressed folder, BetterZip etc but when opening in the OSX Unarchiver all I get out is a .cpgz file and nothing else.
I've read the ZIP specification over and over again and cross-checked against my headers and everything looks fine. I did find another question on here which seemed to have the same issue but the solution was to change the "version needed to extract" field which I did to 0x0014 and I get an "operation not permitted" error when trying to unzip.
I've uploaded a sample zip file with a folder and a small image inside to here:
http://www.freefilehosting.net/test_97
Here is how the code works:
// File entry header
echo pack('V', 0x04034b50);
echo pack('v', 0x0014); // Version needed to extract
echo pack('v', $dir ? 0 : 0x0808); // General purpose bit flag for unknown CRC
echo pack('v', 0x00); // Compression method (store)
echo pack('V', $dts); // DOS timestamp
echo pack('V', 0x00); // CRC - empty
echo pack('V', 0x00); // Compressed data length
echo pack('V', 0x00); // Decompressed data length
echo pack('v', strlen($filename)); // Length of filename
echo pack('v', 0x00); // Length of additional data
<snip>Output raw file data</snip>
// File entry trailer
echo pack('V', 0x08074b50); // Magic
echo pack('V', $crc); // CRC generated using crc32b algo
echo pack('V', $data_size); // Compressed size
echo pack('V', $total_size); // Uncompressed size
// CDR record
echo pack('V', 0x02014b50); // Magic
echo pack('v', 0x0014); // Version created by
echo pack('v', 0x0014); // Version req'd to open
echo pack('v', 0x00); // General purpose bit
echo pack('v', 0x00); // Compression method (store)
echo pack('V', $dts); // DOS timestamp
echo pack('V', $crc); // CRC of data
echo pack('V', $data_size); // Compressed size
echo pack('V', $total_size); // Uncompressed size
echo pack('v', strlen($filename)); // Filename length
echo pack('v', 0x00); // Extra data length
echo pack('v', 0x00); // Comment length
echo pack('v', 0x00); // Start disk no.
echo pack('v', 0x00); // Internal file attributes
echo pack('V', $dir ? 16 : 32); // External file attributes
echo pack('V', $offset); // Relative offset
// End of file record
echo pack('V', 0x06054b50); // Magic
echo pack('v', 0x00); // Current disk number
echo pack('v', 0x00); // Disk containing CDR
echo pack('v', $count); // Number of entries in this CDR
echo pack('v', $count); // Total number of CDR entries
echo pack('V', $cdr_len); // Length of CDR
echo pack('V', $cdr_offset); // Offset of CDR
echo pack('v', 0x00); // Zip file comment length