I am trying to offer download of a whole directory from an apache using php I use the answer from this question Zip Stream in PHP
But when I compare (with cksum) the downloaded zip and the zip created with the same command from the command line the resuts are different.
Here is what I do from PHP :
<?php
$dir = "/path/to/myfolder";
$ficzip = basename($name) . ".zip";
header('Content-Transfer-Encoding: binary');
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . $ficzip. '"');
chdir( $dir );
$stream = popen( "/usr/bin/zip -qr -1 - .", "r" );
if( $stream )
{
fpassthru( $stream );
fclose( $stream );
}
?>
Here is what I do from the command line :
cd "/path/to/myfolder"
/usr/bin/zip -qr -1 - . > /tmp/myfolder.zip
I want both cksum are the same but they are not. What am I missing ? What to do so that they are the same ?
EDIT
Here is a diff between zipinfo for both files (on the left downloaded file and on the right command line file).
7,9c7,9
< Zip archive file size: 248145030 (000000000ECA6486h)
< Actual end-cent-dir record offset: 248145008 (000000000ECA6470h)
< Expected end-cent-dir record offset: 248145008 (000000000ECA6470h)
---
> Zip archive file size: 248144998 (000000000ECA6466h)
> Actual end-cent-dir record offset: 248144976 (000000000ECA6450h)
> Expected end-cent-dir record offset: 248144976 (000000000ECA6450h)
16c16
< is 248144779 (000000000ECA638Bh).
---
> is 248144747 (000000000ECA636Bh).
31c31
< compression sub-type (deflation): normal
---
> compression sub-type (deflation): fast
33c33
< extended local header: yes
---
> extended local header: no
59,60d58
< There are an extra 16 bytes preceding this file.
<
63,64c61,62
< offset of local header from start of archive: 248143809
< (000000000ECA5FC1h) bytes
---
> offset of local header from start of archive: 248143793
> (000000000ECA5FB1h) bytes
70c68
< compression sub-type (deflation): normal
---
> compression sub-type (deflation): fast
72c70
< extended local header: yes
---
> extended local header: no
EDIT2
replacing the -1
for fastest compression by -Z store
for no compression reduces the differences, but still not OK.
7,9c7,9
< Zip archive file size: 249693306 (000000000EE2047Ah)
< Actual end-cent-dir record offset: 249693284 (000000000EE20464h)
< Expected end-cent-dir record offset: 249693284 (000000000EE20464h)
---
> Zip archive file size: 249693274 (000000000EE2045Ah)
> Actual end-cent-dir record offset: 249693252 (000000000EE20444h)
> Expected end-cent-dir record offset: 249693252 (000000000EE20444h)
16c16
< is 249693055 (000000000EE2037Fh).
---
> is 249693023 (000000000EE2035Fh).
32c32
< extended local header: yes
---
> extended local header: no
58,59d57
< There are an extra 16 bytes preceding this file.
<
62,63c60,61
< offset of local header from start of archive: 249690256
< (000000000EE1F890h) bytes
---
> offset of local header from start of archive: 249690240
> (000000000EE1F880h) bytes
70c68
< extended local header: yes
---
> extended local header: no
Solution
Here is the command I am using to get identical results. I keep the question opened so that someone can explain differences between popen and terminal execution of the command.
/usr/bin/zip -qr -0 -fd -fz- - .